JComponent () { if (myMainPanel == null){ myMainPanel = new JPanel(new GridBagLayout()){ @Override public Dimension getPreferredSize(){ return getMainPanelPreferredSize(super.getPreferredSize()); } }; myAttrPanel = new JPanel(new GridBagLayout()); JPanel myScrollPanel = new JPanel(new GridBagLayout()); updateShown(); myScrollPanel.setBorder(null); int attrCount = myUnsetAttributes.length; if (myMustEnterName && !Arrays.asList(myUnsetAttributes).contains(FileTemplate.ATTRIBUTE_NAME)) { attrCount++; } Insets insets = (attrCount > 1) ? JBUI.insets(2) : JBInsets.emptyInsets(); myScrollPanel.add(myAttrPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insets, 0, 0)); if (attrCount > 1) { myScrollPanel.add(new JPanel(), new GridBagConstraints(0, 1, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, JBUI.insets(2), 0, 0)); JScrollPane attrScroll = ScrollPaneFactory.createScrollPane(myScrollPanel, true); attrScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); attrScroll.setViewportBorder(null); myMainPanel.add(attrScroll, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, JBUI.insets(2), 0, 0)); } else { myMainPanel.add(myScrollPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, JBInsets.emptyInsets(), 0, 0)); } } return myMainPanel; }