Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
private class CellRenderer extends JLabel implements ListCellRenderer {
public TypeCellRenderer() {
setOpaque(true);
}
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
MyItemModel model = (MyItemModel)value;
setText(model.getText());
setEnabled(model.isEnabled());
/* Farben: */
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
/* Rückgabe: */
return this;
}
}
private class ItemActionListener implements ActionListener {
/* Verweise: */
private JComboBox comboBox;
private MyItemModel currentItem;
public ItemActionListener(final JComboBox comboBox) {
this.comboBox = comboBox;
currentItem = (MyItemModel)comboBox.getSelectedItem();
}
public void actionPerformed(final ActionEvent arg0) {
MyItemModel tempItem = (MyItemModel)comboBox.getSelectedItem();
if(tempItem.isEnabled()) {
comboBox.setSelectedItem(currentItem);
} else {
currentItem = tempItem;
}
}
}
combo.setCellRenderer(new CellRenderer());
combo.addActionListener(new ItemActionListener(combo));