This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
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 Make it so: Java DB Connections & Transactions this week in the JDBC 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="" target="_blank" rel="nofollow"></a>
Consider Paul's rocket mass heater.
subject: size of JComboBox
It's not a secret anymore!