Reputation: 10474
For a project I have an almost working code, but I do not have the GUI. I want to make a screen that consists of clickable labels and has the following design:
I was thinking about first making the middle GridBagLayout
with with a dimension of 6 by 2. Then 'wrapping' that up and adding the two buttons to the side, and then 'wrapping' that and adding the two buttons below.
I am inexperienced with Swing, and I have no idea how to start. I hope someone can give me some hints in the right direction.
Upvotes: 1
Views: 125
Reputation: 205775
Several approaches to a very similar layout using GridBagLayout
and/or nesting are shown here. Consider using JButton
for each clickable area, rather than JLabel
. If you go with a nested layout,
Use BorderLayout
for the enclosing panel.
Add buttons to EAST
and WEST
for the leftmost and rightmost areas.
Add a GridLayout(1, 2)
of buttons to SOUTH
for the bottom row.
Add a GridLayout(2, 6)
of buttons to CENTER
for the central twelve areas.
Addendum: A critical issue will be what you want the resize behavior to be.
Upvotes: 3
Reputation: 291
as said in the comments above you could (should ?) use the WYSIWYG Window Builder plugin available for Eclipse; it's simple to use.
However, that doesn't answer your question, so to do so, here is how I would structure the UI if I were to make one like that : http://www.hostingpics.net/viewer.php?id=902716gZHkK26.jpg
I basically use BoxLayout because that's the one I'm most familiar with. Every Rectangle is a JPanel. I think the image is pretty self eplanatory.
Upvotes: 1