jdk/test/javax/swing/JTableHeader/6884066/bug6884066.java
author yan
Thu, 18 Jun 2015 11:05:33 +0300
changeset 31442 5f0b1f795848
parent 28071 3acb75b8df45
child 40128 e635645d2a8a
permissions -rw-r--r--
8081306: [TEST_BUG] remove imports of the internal API from some regression tests Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5590
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
     1
/*
6374
e214162c907e 6982137: Rebranding pass 2 - missed copyright changes
ohair
parents: 5590
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
5590
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
     4
 *
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
     8
 *
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    13
 * accompanied this code).
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    14
 *
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    18
 *
6374
e214162c907e 6982137: Rebranding pass 2 - missed copyright changes
ohair
parents: 5590
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e214162c907e 6982137: Rebranding pass 2 - missed copyright changes
ohair
parents: 5590
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e214162c907e 6982137: Rebranding pass 2 - missed copyright changes
ohair
parents: 5590
diff changeset
    21
 * questions.
5590
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    22
 */
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    23
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    24
/* @test
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    25
   @bug 6884066
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    26
   @summary JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    27
   @author Alexander Potochkin
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    28
   @run main bug6884066
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    29
*/
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    30
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    31
import javax.swing.*;
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    32
import javax.swing.table.JTableHeader;
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    33
import javax.swing.table.TableColumnModel;
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    34
import javax.swing.table.TableColumn;
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    35
import java.awt.*;
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    36
import java.awt.event.InputEvent;
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    37
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    38
public class bug6884066 {
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    39
    private static JTableHeader header;
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    40
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    42
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    43
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    44
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    45
        Robot robot = new Robot();
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    46
        robot.setAutoDelay(20);
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    47
        SwingUtilities.invokeAndWait(new Runnable() {
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    48
            public void run() {
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    49
                // just to quickly grab a column model
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    50
                JTable table = new JTable(10, 5);
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    51
                header = new JTableHeader(table.getColumnModel());
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    52
                checkColumn(0, "A");
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    53
                JFrame frame = new JFrame("standalone header");
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    54
                frame.add(header);
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    55
                frame.pack();
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    56
                frame.setVisible(true);
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    57
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    58
            }
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    59
        });
28071
3acb75b8df45 8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 6374
diff changeset
    60
        robot.waitForIdle();
5590
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    61
        Point point = header.getLocationOnScreen();
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    62
        robot.mouseMove(point.x + 3, point.y + 3);
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    63
        robot.mousePress(InputEvent.BUTTON1_MASK);
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    64
        for (int i = 0; i < header.getWidth() - 3; i++) {
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    65
            robot.mouseMove(point.x + i, point.y + 3);
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    66
        }
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    67
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    68
        SwingUtilities.invokeAndWait(new Runnable() {
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    69
            public void run() {
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    70
                TableColumnModel model = header.getColumnModel();
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    71
                checkColumn(model.getColumnCount() - 1, "A");
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    72
            }
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    73
        });
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    74
    }
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    75
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    76
    private static void checkColumn(int index, String str) {
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    77
        TableColumnModel model = header.getColumnModel();
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    78
        Object value = model.getColumn(index).getHeaderValue();
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    79
        if (!str.equals(value)) {
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    80
            throw new RuntimeException("Unexpected header's value; " +
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    81
                    "index = " + index + " value = " + value);
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    82
        }
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    83
    }
3ec077d7e893 6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff changeset
    84
}