• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Forcing size of JPanel

 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to create a color panel behind some JLabels for visual feedback on a process. The problem I'm having is that the panel automatically resizes to fit the labels, regardless of any of the size settings.

This is a data collection program running on our factory floor collecting data from some wireless barcode scanners. The labels provide detailed status of the process is you are standing near the monitor, but the colored panel provides feedback the operators can see across the shop floor.

I've sucessfully set the size of the labels based on a percentage of the parent JFrame, but even if I set the color panel to 90% of the frame width, it automatically downsizes to just contain the labels.

Is there any way to force a panel to be certain size and not automatically shrink to fit the contained elements? Or, is there some other way to do what I'm trying to do?

TIA,
[ January 27, 2005: Message edited by: Tom Blough ]
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tom,


Best regards,
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops ;-)

You may look at the setPreferredSize(java.awt.Dimension) method. look
here for details.
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup, already tried setPreferredSize and setMinimumSize. Panels seem to ignore these and automatically resize to fit the contained items.

Cheers,
[ January 27, 2005: Message edited by: Tom Blough ]
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think your problem is actually with your LayoutManager.

You can set a panels layout manager to null.

Do that, and then set the size of your panel to whatever you like. Just remember that any components you place on that panel will now have to have their locations specified also.
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Jefff. That does work, but is a PITA. Are there any layout managers that do not pack the components before displaying, or any way to disable packing for a given layout manager?

TIA,
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not that I know of.

It's less of a PITA if you use a IDE that has some sort of graphical design module.

I use JBuilder and it seems to easy enough to get along with.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have you included a frame.pack() or just pack() (if extending JFrame)
this will (generally) set everything to their preferred size
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
reply
    Bookmark Topic Watch Topic
  • New Topic