wood burning stoves*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "size of JComboBox" Watch "size of JComboBox" New topic

size of JComboBox

Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109

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

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


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

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>
It is sorta covered in the JavaRanch Style Guide.
subject: size of JComboBox
Similar Threads
jtable problem please help
ComboBox Item Display
JComboBox doubt
small swings problem
combobox rendered in a Jtable