Reputation: 295
I am having a problem using GridBagLayout, I cant seem to get a hang of it. below is what my GUI should look like, I cant seem to get it working. The main problem is lining the text boxes & labels at the right & left hand side.
Upvotes: 1
Views: 636
Reputation: 168815
Probably a nested layout. For the 'groups of controls' on the top left and the right hand side, swap them all for a JTable
1 each or use GroupLayout
2.
Upvotes: 2
Reputation: 656
If you are using eclipse, I'd suggest using Window Builder Pro to get the UI where you you want it. You'll be able to see all the 'dials' you can turn with Gridbag layout.
You'll probably need to play with how things are anchored to get the labels to line up how you want.
Upvotes: 1
Reputation: 51445
I would have a main JPanel that uses the BorderLayout.
Then I would have two subordinate JPanels, one added to the main JPanel using BorderLayout.WEST, and the other added to the main JPanel using BorderLayout.EAST.
The west JPanel would use the GridBagLayout, 4 columns and 4 rows. I would use Insets to get the spacing that I want.
The east JPanel would use the GridBagLayout, 4 columns and 6 rows. Again, I would use Insets to get the spacing that I want.
I would put the buttons inside of a JPanel that uses FlowLayout. I'd set the preferred size of the JPanel so the buttons stay on the same row. Then I'd add the button JPanel to the east JPanel as the 6th row.
Upvotes: 1