Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

size of JComboBox

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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));
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic