File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes  How to fix ListBox and Panel size .. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark " How to fix ListBox and Panel size .." Watch " How to fix ListBox and Panel size .." New topic

How to fix ListBox and Panel size ..

Alex Iordache
Ranch Hand

Joined: Mar 13, 2001
Posts: 62
How to fix ListBox and Panel size in an applet using GridBagLayout as Layout manager?
I have an applet with a Panel and two ListBoxes in the Panel. The layout manager I use is GridBagLayout.
When I populate the listboxes with data (string). Their size (both the panel and listbox) vary with the length of data string. How can I fix the size of these listboxes and panel? How can utilize the preferredSize() and getPreferredSize() methods? Will they help? Thanks in advance.
eric moon
Ranch Hand

Joined: Nov 26, 2000
Posts: 133
gridbag layout references getPreferredSize, and getMinimumSize (info courtesy of Professional Java Programming, WROX press, thanks Java Ranch!) so you will need to set both of them to the size you want. Ie:
combo.setMinimumSize(100, 20);

<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>"Those who cast the votes decide nothing. Those who count the<BR>votes decide<BR>everything." <BR> -Joseph Stalin<HR></BLOCKQUOTE>
I agree. Here's the link:
subject: How to fix ListBox and Panel size ..
jQuery in Action, 3rd edition