Path: blob/master/test/jdk/javax/swing/JTable/6777378/bug6777378.java
41154 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 677737827@summary NullPointerException in XPDefaultRenderer.paint()28@author Alexander Potochkin29@run main bug677737830*/3132import javax.swing.*;33import javax.swing.table.AbstractTableModel;34import javax.swing.table.JTableHeader;35import javax.swing.plaf.metal.MetalLookAndFeel;36import java.awt.event.MouseEvent;37import java.awt.event.InputEvent;38import java.awt.*;3940public class bug6777378 {41private static JFrame frame;42private static JTableHeader header;4344public static void main(String[] args) throws Exception {45try {46Robot robot = new Robot();47robot.setAutoDelay(20);48SwingUtilities.invokeAndWait(new Runnable() {49public void run() {50try {51UIManager.setLookAndFeel(new MetalLookAndFeel());52} catch (Exception e) {53e.printStackTrace();54}55JTable table = new JTable(new AbstractTableModel() {56public int getRowCount() {57return 10;58}5960public int getColumnCount() {61return 10;62}6364public Object getValueAt(int rowIndex, int columnIndex) {65return "" + rowIndex + " " + columnIndex;66}67});6869header = new JTableHeader(table.getColumnModel());70header.setToolTipText("hello");7172frame = new JFrame();73frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);74frame.add(header);7576frame.setSize(300, 300);77frame.setVisible(true);78}79});80robot.waitForIdle();81Point point = header.getLocationOnScreen();82robot.mouseMove(point.x + 20, point.y + 50);83robot.mouseMove(point.x + 30, point.y + 50);84robot.mousePress(InputEvent.BUTTON1_MASK);85robot.mouseRelease(InputEvent.BUTTON1_MASK);86} finally {87if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());88}89}90}919293