• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JPanel and LayoutManager

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey

My program fills a panel with checkboxes dynamically and I want the panel to stretch accordingly to the amount of content,
this works fine as long as I keep the window at the same size at runtime as I do when I'm working in NetBeans. However, if I
try to maximize the window, the panel suddenly gets greedy and takes up a lot of extra space beneath the checkboxes, without
actually putting anything else in there.

Any suggestions as to how I could solve this? I've been using a BoxLayout with the vertical resizable on the aforementioned panel.
 
Bartender
Posts: 15741
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you will have to decide what you do want to do with the extra space.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if I try to maximize the window



Thats what maximizing does, it maximizes the vertical and horizontal areas.

For more help create a SSCCE that demonstrates the incorrect behaviour.
 
Tom Sakra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, but it doesn't maximize it completely either. It just uses about 200 pixels more than it should when I maximize the window.
So there's still room for it to stretch more, which doesn't make any sense as to why it just randomly stops, but I'd rather it stopped
stretching after the panel was filled. So is there any way to decide the size of the panel without using the vertical resizable option?

Edit:
Thanks for the help guys, but I just did what I asked for in the last line above :P Just added the preferredSize (height) of the given
checkboxes to a variable and adjusted the panel size to that variable, and using the BoxLayout with the page axis.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use layout managers correctly, you should never have to adjust a size manually.

I encourage you to post a SSCCE, as Rob already asked, so others here can study it and advise you how to improve it.
 
Tom Sakra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course not, but I find creating a relatively large GUI in NetBeans is a bit of a wrestle itself.
Since I'm using NetBeans to create the GUI, I'm pretty sure that creating that exact part
would've been easier manually. But I'm not familiar with using custom components in the NetBeans
GUI editor, so this will have to do for now. I might come back to it later if the schedule allows for it.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic