Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTableHeader/6889007/bug6889007.java
38854 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/* @test24@bug 688900725@summary No resize cursor during hovering mouse over JTable26@author Alexander Potochkin27*/2829import javax.swing.*;30import javax.swing.plaf.basic.BasicTableHeaderUI;31import javax.swing.table.JTableHeader;32import java.awt.*;3334public class bug6889007 {3536public static void main(String[] args) throws Exception {37Robot robot = new Robot();38robot.setAutoDelay(20);3940final JFrame frame = new JFrame();41frame.setUndecorated(true);4243SwingUtilities.invokeAndWait(new Runnable() {44public void run() {45frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4647JTableHeader th = new JTableHeader();48th.setColumnModel(new JTable(20, 5).getColumnModel());4950th.setUI(new MyTableHeaderUI());5152frame.add(th);53frame.pack();54frame.setLocationRelativeTo(null);55frame.setVisible(true);56}57});58robot.waitForIdle();59Point point = frame.getLocationOnScreen();60int shift = 10;61int x = point.x;62int y = point.y + frame.getHeight()/2;63for(int i = -shift; i < frame.getWidth() + 2*shift; i++) {64robot.mouseMove(x++, y);65}66robot.waitForIdle();67// 9 is a magic test number68if (MyTableHeaderUI.getTestValue() != 9) {69throw new RuntimeException("Unexpected test number "70+ MyTableHeaderUI.getTestValue());71}72System.out.println("ok");73}7475static class MyTableHeaderUI extends BasicTableHeaderUI {76private static int testValue;7778protected void rolloverColumnUpdated(int oldColumn, int newColumn) {79increaseTestValue(newColumn);80Cursor cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);81if (oldColumn != -1 && newColumn != -1 &&82header.getCursor() != cursor) {83throw new RuntimeException("Wrong type of cursor!");84}85}8687private static synchronized void increaseTestValue(int increment) {88testValue += increment;89}9091public static synchronized int getTestValue() {92return testValue;93}94}95}969798