jdk/test/javax/swing/JComboBox/8019180/Test8019180.java
author alexsch
Fri, 31 Oct 2014 00:40:14 +0400
changeset 27505 bc197defe284
parent 25110 e1f2746b6439
child 46151 5fa789776f7d
permissions -rw-r--r--
8057893: JComboBox actionListener never receives "comboBoxEdited" from getActionCommand Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25110
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
     1
/*
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
     4
 *
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
     8
 *
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    13
 * accompanied this code).
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    14
 *
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    18
 *
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    21
 * questions.
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    22
 */
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    23
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    24
import java.util.concurrent.CountDownLatch;
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    25
import javax.swing.JComboBox;
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    26
import javax.swing.JFrame;
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    27
import javax.swing.SwingUtilities;
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    28
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    29
/*
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    30
 * @test
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    31
 * @bug 8019180
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    32
 * @summary Tests that combobox works if it is used as action listener
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    33
 * @author Sergey Malenkov
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    34
 */
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    35
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    36
public class Test8019180 implements Runnable {
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    37
    private static final CountDownLatch LATCH = new CountDownLatch(1);
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    38
    private static final String[] ITEMS = {"First", "Second", "Third", "Fourth"};
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    39
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    40
    public static void main(String[] args) throws InterruptedException {
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    41
        SwingUtilities.invokeLater(new Test8019180());
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    42
        LATCH.await();
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    43
    }
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    44
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    45
    private JComboBox<String> test;
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    46
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    47
    @Override
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    48
    public void run() {
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    49
        if (this.test == null) {
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    50
            this.test = new JComboBox<>(ITEMS);
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    51
            this.test.addActionListener(this.test);
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    52
            JFrame frame = new JFrame();
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    53
            frame.add(test);
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    54
            frame.pack();
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    55
            frame.setVisible(true);
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    56
            SwingUtilities.invokeLater(this);
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    57
        } else {
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    58
            int index = this.test.getSelectedIndex();
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    59
            this.test.setSelectedIndex(1 + index);
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    60
            if (0 > this.test.getSelectedIndex()) {
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    61
                System.err.println("ERROR: no selection");
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    62
                System.exit(8019180);
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    63
            }
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    64
            SwingUtilities.getWindowAncestor(this.test).dispose();
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    65
            LATCH.countDown();
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    66
        }
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    67
    }
e1f2746b6439 8019180: Use JComboBox as it's own ActionListener leads to unexpected behaviour
malenkov
parents:
diff changeset
    68
}