FormBuilder (@Nullable JComponent label, @NotNull JComponent component, int topInset, boolean labelOnTop, boolean fillVertically) { GridBagConstraints c = new GridBagConstraints(); topInset = myLineCount > 0 ? topInset : 0; if (myVertical || labelOnTop || label == null) { c.gridwidth = 2; c.gridx = 0; c.gridy = myLineCount; c.weightx = 0; c.weighty = 0; c.fill = NONE; c.anchor = getLabelAnchor(false, fillVertically); c.insets = JBUI.insets(topInset, myFormLeftIndent, DEFAULT_VGAP, 0); if (label != null) myPanel.add(label, c); c.gridx = 0; c.gridy = myLineCount + 1; c.weightx = 1.0; c.weighty = getWeightY(fillVertically); c.fill = getFill(component, fillVertically); c.anchor = WEST; c.insets = JBUI.insets(label == null ? topInset : 0, myFormLeftIndent, 0, 0); myPanel.add(component, c); myLineCount += 2; } else { c.gridwidth = 1; c.gridx = 0; c.gridy = myLineCount; c.weightx = 0; c.weighty = 0; c.fill = NONE; c.anchor = getLabelAnchor(true, fillVertically); c.insets = JBUI.insets(topInset, myFormLeftIndent, 0, myHorizontalGap); myPanel.add(label, c); c.gridx = 1; c.weightx = 1; c.weighty = getWeightY(fillVertically); c.fill = getFill(component, fillVertically); c.anchor = WEST; c.insets = JBUI.insets(topInset, 0, 0, 0); myPanel.add(component, c); myLineCount++; } return this; }