Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to set a fixed size for a JComboBox  RSS feed

 
kamilla miesak
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created an editable JComboBox that stores regular expressions. When the application is running all newly entered expresssions are being stored in a Vector, and at the closing of the application the contents of that Vector are transferred to a file. When the application is started again, contents of that file are transferred back to a Vector and the JComboBox is populated with its contents.
I can enter the expressions of any length into the JComboBox without the size of JComboBox being affected, but when I restart the application and have the contents of the JComboBox be populated with what's in the Vector again, the JComboBox expands its boundaries to fit an entire length of a particular expression. Since some of these expressions can be quite lengthy - my entire interface is affected. I've tried setSize(), setMaximum() and setPreferred() methods and nothing seems to be working. Any ideas what might solve the problem?
Thanks,
Kamilla
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the size of a component is defined by the layout manager. what LayoutManager are you using?
in 1.4 you could set a default value for the combo box, calling setPrototypeDisplayValue(Object). the combo will have the wide of this value.
nevertheless the combobox does not display a horizontal scrollbar. only the first part of the value will be visible. if you'd like to have horizontal scrolling, you most likely will have to extend the ComboBoxUI class (see the API).
 
kamilla miesak
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a way to make it work in 1.3?
I'm using GridBagLayout right now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!