use of javax.swing.ComboBoxEditor in project jdk8u_jdk by JetBrains.
the class Test8015300 method main.
public static void main(String[] args) throws Exception {
UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels();
for (UIManager.LookAndFeelInfo info : array) {
UIManager.setLookAndFeel(info.getClassName());
System.err.println("L&F: " + info.getName());
invokeAndWait(new Runnable() {
@Override
public void run() {
combo = new JComboBox<>(ITEMS);
combo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent event) {
if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) {
ComboBoxEditor editor = combo.getEditor();
Object component = editor.getEditorComponent();
if (component instanceof JTextField) {
JTextField text = (JTextField) component;
boolean selected = null != text.getSelectedText();
StringBuilder sb = new StringBuilder();
sb.append(" - ").append(combo.getSelectedIndex());
sb.append(": ").append(event.getItem());
if (selected) {
sb.append("; selected");
}
System.err.println(sb);
if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) {
throw new Error("unexpected state of text selection");
}
}
}
}
});
JFrame frame = new JFrame(getClass().getSimpleName());
frame.add(combo);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
});
for (int i = 0; i < ITEMS.length; ++i) {
select(i, true);
select(1, false);
}
invokeAndWait(new Runnable() {
@Override
public void run() {
windowForComponent(combo).dispose();
}
});
}
}
use of javax.swing.ComboBoxEditor in project JMRI by JMRI.
the class JmriBeanComboBox method validateText.
// this is called to validate that the text in the textfield
// is a valid member of the managed data.
//note: if _validateMode is true
// if text is valid set textfield background to green else red
// if _validateMode is false
// if text is valid set textfield background to green else yellow
private void validateText() {
ComboBoxEditor cbe = getEditor();
JTextComponent c = (JTextComponent) cbe.getEditorComponent();
String comboBoxText = cbe.getItem().toString();
if (isEditable() && !comboBoxText.isEmpty()) {
if (null != getNamedBean()) {
//pastel green
c.setBackground(new Color(0xBDECB6));
} else if (_validateMode) {
//pastel red
c.setBackground(new Color(0xFFC0C0));
} else {
//pastel yellow
c.setBackground(new Color(0xFDFD96));
}
} else {
//white (pastel grey?)
c.setBackground(new Color(0xFFFFFF));
}
}
Aggregations