wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes size of JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "size of JComboBox" Watch "size of JComboBox" New topic
Author

size of JComboBox

Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109
hi,

hi i am having a JComboBox to display a list of items. when i add an item which is short in length
say

JComboBox cmb=new JComboBox();
cmb.addItem("this is ajay");//length of the string is small

the combo box is small in size .

when i add an String which is large in length

cmb.addItem("this is a big string and the size of the combo is big");

the size of the combobox increaces .

since i have used

frame.pack();

the size of the frame also increaces .

At any point of time i want the size of the combobox to remain same.

Is there any solution for this pblm?

help me plz.
Pat Hays
Ranch Hand

Joined: Aug 20, 2004
Posts: 138
Hi,

You should use setPreferredSize instead of calling setSize, as long as the container is using a LayoutManager. Try the following code.
----------
jComboBox1.setPreferredSize(new Dimension(120, 25));


Download Java GUI Builder, <a href="http://www.mars3000.com" target="_blank" rel="nofollow">http://www.mars3000.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: size of JComboBox