• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Design of JPanel

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
This one time, at bandcamp, I had relations with a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic