List of utility methods to do JComboBox
void | setupComboBoxMaxRows(T inComboBox) Set the maximum number of rows for a JComboBox so that it always can fit on the screen BasicComboPopup popup = (BasicComboPopup) inComboBox.getAccessibleContext().getAccessibleChild(0); JList list = popup.getList(); ListModel lm = list.getModel(); ListCellRenderer renderer = list.getCellRenderer(); int maxItemHeight = 12; for (int i = 0; i < lm.getSize(); ++i) { Object value = lm.getElementAt(i); Component c = renderer.getListCellRendererComponent(list, value, i, false, false); ... |
void | updateContents(@SuppressWarnings("rawtypes") JComboBox box, Object[] options) update Contents box.removeAllItems();
for (Object o : options)
box.addItem(o);
|
void | updateGooseChooser(JComboBox gooseChooser, String callingGoose, String[] allGeese) Updates the UI to show the current list of geese. if (gooseChooser == null || allGeese == null) return; String savedItem = (String) gooseChooser.getSelectedItem(); Arrays.sort(allGeese); DefaultComboBoxModel model = (DefaultComboBoxModel) gooseChooser.getModel(); model.removeAllElements(); model.addElement("Boss"); for (String gooseName : allGeese) { ... |