Search in sources :

Example 1 with WindowsComboBoxEditor

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();
            }
        });
    }
}
Also used : ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) UIManager(javax.swing.UIManager) JTextField(javax.swing.JTextField) ComboBoxEditor(javax.swing.ComboBoxEditor) WindowsComboBoxEditor(com.sun.java.swing.plaf.windows.WindowsComboBoxUI.WindowsComboBoxEditor) WindowsComboBoxEditor(com.sun.java.swing.plaf.windows.WindowsComboBoxUI.WindowsComboBoxEditor) JFrame(javax.swing.JFrame) ItemListener(java.awt.event.ItemListener)

Aggregations

WindowsComboBoxEditor (com.sun.java.swing.plaf.windows.WindowsComboBoxUI.WindowsComboBoxEditor)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 ComboBoxEditor (javax.swing.ComboBoxEditor)1 JComboBox (javax.swing.JComboBox)1 JFrame (javax.swing.JFrame)1 JTextField (javax.swing.JTextField)1 UIManager (javax.swing.UIManager)1