• Post Reply Bookmark Topic Watch Topic
  • New Topic

Design of JPanel

 
Martin Vietor
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,

I have two JPanels (GridLayouts), one has 15 JCheckBoxes, the other 13. Both have a JButton at the Bottom. I would like the CheckBoxes in each JPanel to be at the same Height (just looks prettier) and both Buttons at the very Bottom. I have achieved this by



Pragmatic. Not very elegant. Is there a way? GridBagLayout and then set GridBagConstraints for the CheckBoxes and the Button to spread them out? Seems awfully complicated. Is there some really cool and easy way to do it that I can't think of?

Thanks, Martin
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you reasonably competent at GridBagLayout, you would have been using it,
which means it will only cause you grief (like most of the rest of us).

you could nest a few panels of differing layoutManagers to achieve the same effect.

the easiest way is what you have done.
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Martin Vietor:
Hello again,

I have two JPanels (GridLayouts), one has 15 JCheckBoxes, the other 13. Both have a JButton at the Bottom. I would like the CheckBoxes in each JPanel to be at the same Height (just looks prettier) and both Buttons at the very Bottom. I have achieved this by



Pragmatic. Not very elegant. Is there a way?


Well you can leave the string out and just do new JLabel(), or you can use something like Box.createHorizontalStrut(0).

If you don't like using components as spacers, you can put the GridLayout panel in NORTH of a BorderLayout and put the buttons in a SOUTH panel. That's probably what I would have done.

You mention GridBagLayout. While that should work, I wouldn't recommend it.
 
Martin Vietor
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting. I thought GridBagLayout was what all the hip kids use and Border-, Flow-, or somesuch was for us newbies Most of my layout uses GridBag, too many Panels of different size that get stretched into funny shapes otherwise. Is there an actual reason against GridBag or is it just too complicated if not used on a regular basis?

Martin
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Is there an actual reason against GridBag or is it just too complicated if not used on a regular basis?

I find it very frustrating - fix one thing (via changing a constraint), and 2 more things break.
sometimes it feels like I'm just going around in circles trying to get GBL to work,
in the end, far easier to nest a couple of panels with other layouts.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!