Search code examples
javaswingjcomboboxjlistjscrollbar

java jcombobox without scrollbar?


I have a JComboBox component:

ho2Combo = new JComboBox();
ho2Combo.setLocation(x, y);
ho2Combo.setSize(w, h);
ho2Combo.setFont(comboFont);
ho2Combo.setModel(new DefaultComboBoxModel(Format.model(0))); //this fills up the combobox
ho2Combo.setSelectedIndex(0);
ho2Combo.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent evt) {
        ho2ComboItemStateChanged(evt);
     }
});
add(ho2Combo);

And I would love to have this combobox without scrollbar! How could I reach this? Please help! Thanks!


Solution

  • If you're confident that all elements will fit on screen, then you can use:

    ho2Combo.setMaximumRowCount(ho2Combo.getModel().getSize());