2012-07-15 113 views
1

我有一個JComboBox組件:java jcombobox沒有滾動條?

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); 

我很想有此組合框沒有滾動條!我怎麼能達到這個?請幫忙!謝謝!

回答

5

如果您確信所有元素將適合在屏幕上,那麼你可以使用:

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