So I have my labels and everything added, but I am still having trouble formatting and aligning everything. The calculate button should obviously be centered. I get that using gridbag splits the frame into coordinate system and when one column is larger than the others it will adjust the others and will throw it off(Right?). But I can't understand how to even fix this. And still having trouble aligning everything to the left so it doesn't start towards the center.
When compiled heres the window
Here's what I am trying to get it like, I haven't added everything yet.
JPanel p = new JPanel(new GridBagLayout());
GridBagConstraints gc = new GridBagConstraints();
//0 Column
gc.gridx = 0;
gc.gridy = 0;
gc.anchor = GridBagConstraints.EAST;
p.add(new JLabel("Mortgage amount:"),gc);
gc.gridx = 0;
gc.gridy =1;
p.add(new JLabel("Mortgage term:"),gc);
gc.gridx = 0;
gc.gridy = 2;
p.add(new JLabel("Interest rate:"),gc);
gc.gridx = 0;
gc.gridy = 3;
p.add(new JLabel("Mortgage start date:"),gc);
gc.gridx = 0;
gc.gridy= 4;
p.add(new JLabel("Monthly Payments:"),gc);
gc.gridx = 0;
gc.gridy = 7;
p.add(new JLabel("Extra payments"),gc);
gc.gridx = 0;
gc.gridy = 8;
p.add(new JLabel("Adding: "),gc);
gc.gridx = 0;
gc.gridy = 9;
p.add(new JLabel("Adding: "),gc);
gc.gridx = 0;
gc.gridy = 10;
p.add(new JLabel("Adding: "),gc);
gc.gridx = 0;
gc.gridy = 11;
p.add(new JLabel("Changes paid off date to:"),gc);
//1 Column
gc.gridx = 1;
gc.gridy = 0;
p.add(new JLabel("$"),gc);
gc.gridx = 1;
gc.gridy = 4;
p.add(new JLabel("$"),gc);
gc.gridx = 1;
gc.gridy = 8;
p.add(new JLabel("$"),gc);
gc.gridx = 1;
gc.gridy = 9;
p.add(new JLabel("$"),gc);
gc.gridx = 1;
gc.gridy = 10;
p.add(new JLabel("$"),gc);
//2 column
gc.gridx = 2;
gc.gridy = 0;
p.add(new JTextField(8),gc);
gc.gridx = 2;
gc.gridy =1;
p.add(new JTextField(8),gc);
gc.gridx = 2;
gc.gridy = 2;
p.add(new JTextField(8),gc);
gc.gridx = 2;
gc.gridy = 3;
p.add(new JComboBox(month),gc);
gc.gridx= 2;
gc.gridy = 4;
p.add(new JTextField(8),gc);
gc.gridx = 2;
gc.gridy = 8;
p.add(new JTextField(8),gc);
gc.gridx = 2;
gc.gridy = 9;
p.add(new JTextField(8),gc);
gc.gridx = 2;
gc.gridy = 10;
p.add(new JTextField(8),gc);
//3 column
gc.gridx = 3;
gc.gridy = 1;
p.add(new JLabel(" years or "),gc);
gc.gridx = 3;
gc.gridy = 2;
p.add(new JLabel(" % per year"),gc);
gc.gridx = 3;
gc.gridy = 3;
p.add(new JComboBox(days),gc);
gc.gridx = 3;
gc.gridy = 8;
p.add(new JLabel("to your monthly mortgage payment"),gc);
gc.gridx = 3;
gc.gridy = 9;
p.add(new JLabel("as an extra yearly mortgage payment every "),gc);
gc.gridx = 3;
gc.gridy = 10;
p.add(new JLabel("as a one-time payment in "),gc);
//4 column
gc.gridx = 4;
gc.gridy = 1;
p.add(new JTextField(8),gc);
gc.gridx = 4;
gc.gridy=3;
p.add(new JComboBox(years),gc);
//5 column
gc.gridx = 5;
gc.gridy = 1;
p.add(new JLabel(" months"),gc);
gc.gridy=5;
gc.anchor = GridBagConstraints.CENTER;
p.add(new JButton("Calculate"),gc);
add(p, BorderLayout.NORTH);
}
}