Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

size of JComboBox

 
Ajay Xavier
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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));
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic