Search in sources :

Example 1 with AccessibleSelection

use of javax.accessibility.AccessibleSelection in project jdk8u_jdk by JetBrains.

the class Bug8154069 method main.

public static void main(String[] args) throws Exception {
    try {
        try {
            UIManager.setLookAndFeel(new NimbusLookAndFeel());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        SwingUtilities.invokeAndWait(() -> {
            frame = new JFrame();
            String[] petStrings = { "Bird", "Cat" };
            JComboBox<String> cb = new JComboBox<>(petStrings);
            // select Cat
            cb.setSelectedIndex(1);
            frame.add(cb);
            frame.pack();
            try {
                cb.setSelectedIndex(-1);
                int i = cb.getSelectedIndex();
                if (i != -1) {
                    throw new RuntimeException("getSelectedIndex is not -1");
                }
                Object o = cb.getSelectedItem();
                if (o != null) {
                    throw new RuntimeException("getSelectedItem is not null");
                }
                AccessibleContext ac = cb.getAccessibleContext();
                AccessibleSelection as = ac.getAccessibleSelection();
                int count = as.getAccessibleSelectionCount();
                if (count != 0) {
                    throw new RuntimeException("getAccessibleSelection count is not 0");
                }
                Accessible a = as.getAccessibleSelection(0);
                if (a != null) {
                    throw new RuntimeException("getAccessibleSelection(0) is not null");
                }
            } catch (Exception e) {
                exception = e;
            }
        });
        if (exception != null) {
            System.out.println("Test failed: " + exception.getMessage());
            throw exception;
        } else {
            System.out.println("Test passed.");
        }
    } finally {
        SwingUtilities.invokeAndWait(() -> {
            frame.dispose();
        });
    }
}
Also used : JComboBox(javax.swing.JComboBox) AccessibleContext(javax.accessibility.AccessibleContext) AccessibleSelection(javax.accessibility.AccessibleSelection) JFrame(javax.swing.JFrame) NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel) Accessible(javax.accessibility.Accessible)

Aggregations

Accessible (javax.accessibility.Accessible)1 AccessibleContext (javax.accessibility.AccessibleContext)1 AccessibleSelection (javax.accessibility.AccessibleSelection)1 JComboBox (javax.swing.JComboBox)1 JFrame (javax.swing.JFrame)1 NimbusLookAndFeel (javax.swing.plaf.nimbus.NimbusLookAndFeel)1