Path: blob/master/test/jdk/javax/swing/JTableHeader/6884066/bug6884066.java
41153 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24@test25@key headful26@bug 688406627@summary JTableHeader listens mouse in disabled state and doesn't work when not attached to a table28@author Alexander Potochkin29@run main bug688406630*/3132import javax.swing.*;33import javax.swing.table.JTableHeader;34import javax.swing.table.TableColumnModel;35import javax.swing.table.TableColumn;36import java.awt.*;37import java.awt.event.InputEvent;3839public class bug6884066 {40private static JTableHeader header;4142public static void main(String[] args) throws Exception {4344UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());4546Robot robot = new Robot();47robot.setAutoDelay(20);48SwingUtilities.invokeAndWait(new Runnable() {49public void run() {50// just to quickly grab a column model51JTable table = new JTable(10, 5);52header = new JTableHeader(table.getColumnModel());53checkColumn(0, "A");54JFrame frame = new JFrame("standalone header");55frame.add(header);56frame.pack();57frame.setVisible(true);58frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);59}60});61robot.waitForIdle();62Point point = header.getLocationOnScreen();63robot.mouseMove(point.x + 3, point.y + 3);64robot.mousePress(InputEvent.BUTTON1_MASK);65for (int i = 0; i < header.getWidth() - 3; i++) {66robot.mouseMove(point.x + i, point.y + 3);67}68robot.mouseRelease(InputEvent.BUTTON1_MASK);69SwingUtilities.invokeAndWait(new Runnable() {70public void run() {71TableColumnModel model = header.getColumnModel();72checkColumn(model.getColumnCount() - 1, "A");73}74});75}7677private static void checkColumn(int index, String str) {78TableColumnModel model = header.getColumnModel();79Object value = model.getColumn(index).getHeaderValue();80if (!str.equals(value)) {81throw new RuntimeException("Unexpected header's value; " +82"index = " + index + " value = " + value);83}84}85}868788