use of com.sun.java.swing.plaf.windows.WindowsComboBoxUI.WindowsComboBoxEditor 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();
}
});
}
}
Aggregations