I generated a simple GridBagLayout, but when I put the result in a frame, it looks weird.
The components are vertical, but they also replicate horizontally. I'm at my wits end with this and can't see what's wrong, help!
public class GaussianNodePanel extends NodePanel {
public GaussianNodePanel() {
initComponents();
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.add(new GaussianNodePanel());
frame.pack();
frame.setVisible(true);
}
private JTextField coefficientsTextField;
private JTextField sigmaTextField;
private JTextField offsetTextField;
@Override
protected void initComponents() {
JLabel label1 = new JLabel();
coefficientsTextField = new JTextField();
JLabel label2 = new JLabel();
sigmaTextField = new JTextField();
JLabel label3 = new JLabel();
offsetTextField = new JTextField();
//======== this ========
setBorder(new TitledBorder("Properties"));
setLayout(new GridBagLayout());
((GridBagLayout)getLayout()).columnWidths = new int[] {88, 190, 0};
((GridBagLayout)getLayout()).rowHeights = new int[] {23, 0, 0, 0};
((GridBagLayout)getLayout()).columnWeights = new double[] {0.0, 0.0, 1.0E-4};
((GridBagLayout)getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 1.0E-4};
//---- label1 ----
label1.setText("Coefficients:");
add(label1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
new Insets(0, 0, 5, 5), 0, 0));
add(coefficientsTextField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 0), 0, 0));
//---- label2 ----
label2.setText("Sigma:");
add(label2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
new Insets(0, 0, 5, 5), 0, 0));
add(sigmaTextField, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 0), 0, 0));
//---- label3 ----
label3.setText("Offset:");
add(label3, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.EAST, GridBagConstraints.VERTICAL,
new Insets(0, 0, 0, 5), 0, 0));
add(offsetTextField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
}
}