JComponent () { final JPanel wholePanel = new JPanel(); wholePanel.setLayout(new BorderLayout()); myProfilePanelHolder = new JPanel() { @Override public void doLayout() { Rectangle bounds = new Rectangle(getWidth(), getHeight()); JBInsets.removeFrom(bounds, getInsets()); for (Component component : getComponents()) { component.setBounds(bounds); } } @Override public Dimension getPreferredSize() { for (Component component : getComponents()) { if (component.isVisible()) { return component.getPreferredSize(); } } return super.getPreferredSize(); } @Override public Dimension getMinimumSize() { for (Component component : getComponents()) { if (component.isVisible()) { return component.getMinimumSize(); } } return super.getMinimumSize(); } }; wholePanel.add(myProfilePanelHolder, BorderLayout.CENTER); JPanel profilesHolder = new JPanel(); profilesHolder.setLayout(new CardLayout()); myAbstractSchemesPanel = new InspectionProfileSchemesPanel(getProject(), myApplicationProfileManager, myProjectProfileManager, this); wholePanel.add(myAbstractSchemesPanel, BorderLayout.NORTH); return wholePanel; }