Path: blob/master/test/jdk/javax/swing/JTableHeader/6889007/bug6889007.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 688900727@summary No resize cursor during hovering mouse over JTable28@author Alexander Potochkin29*/3031import javax.swing.*;32import javax.swing.plaf.basic.BasicTableHeaderUI;33import javax.swing.table.JTableHeader;34import java.awt.*;3536public class bug6889007 {3738public static void main(String[] args) throws Exception {39Robot robot = new Robot();40robot.setAutoDelay(20);4142final JFrame frame = new JFrame();43frame.setUndecorated(true);4445SwingUtilities.invokeAndWait(new Runnable() {46public void run() {47frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4849JTableHeader th = new JTableHeader();50th.setColumnModel(new JTable(20, 5).getColumnModel());5152th.setUI(new MyTableHeaderUI());5354frame.add(th);55frame.pack();56frame.setLocationRelativeTo(null);57frame.setVisible(true);58}59});60robot.waitForIdle();61Point point = frame.getLocationOnScreen();62int shift = 10;63int x = point.x;64int y = point.y + frame.getHeight()/2;65for(int i = -shift; i < frame.getWidth() + 2*shift; i++) {66robot.mouseMove(x++, y);67}68robot.waitForIdle();69// 9 is a magic test number70if (MyTableHeaderUI.getTestValue() != 9) {71throw new RuntimeException("Unexpected test number "72+ MyTableHeaderUI.getTestValue());73}74System.out.println("ok");75}7677static class MyTableHeaderUI extends BasicTableHeaderUI {78private static int testValue;7980protected void rolloverColumnUpdated(int oldColumn, int newColumn) {81increaseTestValue(newColumn);82Cursor cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);83if (oldColumn != -1 && newColumn != -1 &&84header.getCursor() != cursor) {85throw new RuntimeException("Wrong type of cursor!");86}87}8889private static synchronized void increaseTestValue(int increment) {90testValue += increment;91}9293public static synchronized int getTestValue() {94return testValue;95}96}97}9899100