Home| New Wiki | | Login | User registry | Home Tree PDF
PaperJComboBoxList
Owner:csilva, Version: 1, Date:Mon 05, June 2006,

The common question "How do I create a JComboBox with a horizontal scrollbar?", seems to be regarded as bad UI technique by sun http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5091278.

So, what happens if we need that?

Actually, I agree that having scrollbars on a combobox list is extremelly disconcerting. But still, there is a problem related to the lack of control about sizes.

Edit a code but show a description

My main concern is how to show a list with descriptions, but present a code on the combo editor. The problem is that the list is always the same size of the combo, but a simple trick can solve it, just redefine the getSize() method:

public Dimension getSize() {
  return ui.getPreferredSize(this);
}

the getSize is not called very often, at least not with the common layout managers and seems to be safely ovewriten.

Now, to how the code of the item instead of the description, we just need to overwrite the configureEditor() method:

public void configureEditor(ComboBoxEditor anEditor, Object anItem) {
  if (anItem != null) {
    super.configureEditor(anEditor, ((MyBean) anItem).getCode());
    setToolTipText(((MyBean) anItem).getDescription());
  } else {
    super.configureEditor(anEditor, anItem);
    setToolTipText("Carried code...");
  }
}


Edit - History - Extract PDF - Extract Tree as PDF

Last Modified

Thu, Nov 19 Sat, Oct 3 Fri, Sep 25 Mon, Aug 3 Mon, Apr 27 Sat, Mar 28 Mon, Jan 19 Tue, Jan 6

Home| New Wiki