1 /*
   2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25    @bug 6777378
  26    @summary NullPointerException in XPDefaultRenderer.paint()
  27    @author Alexander Potochkin
  28    @run main bug6777378
  29 */
  30 
  31 import javax.swing.*;
  32 import javax.swing.table.AbstractTableModel;
  33 import javax.swing.table.JTableHeader;
  34 import javax.swing.plaf.metal.MetalLookAndFeel;
  35 import java.awt.event.MouseEvent;
  36 import java.awt.event.InputEvent;
  37 import java.awt.*;
  38 
  39 public class bug6777378 {
  40     private static JFrame frame;
  41     private static JTableHeader header;
  42 
  43     public static void main(String[] args) throws Exception {
  44         Robot robot = new Robot();
  45         robot.setAutoDelay(20);
  46         SwingUtilities.invokeAndWait(new Runnable() {
  47             public void run() {
  48                 try {
  49                     UIManager.setLookAndFeel(new MetalLookAndFeel());
  50                 } catch (Exception e) {
  51                     e.printStackTrace();
  52                 }
  53                 JTable table = new JTable(new AbstractTableModel() {
  54                     public int getRowCount() {
  55                         return 10;
  56                     }
  57 
  58                     public int getColumnCount() {
  59                         return 10;
  60                     }
  61 
  62                     public Object getValueAt(int rowIndex, int columnIndex) {
  63                         return "" + rowIndex + " " + columnIndex;
  64                     }
  65                 });
  66 
  67                 header = new JTableHeader(table.getColumnModel());
  68                 header.setToolTipText("hello");
  69 
  70                 frame = new JFrame();
  71                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  72                 frame.add(header);
  73 
  74                 frame.setSize(300, 300);
  75                 frame.setVisible(true);
  76             }
  77         });
  78         robot.waitForIdle();
  79         Point point = header.getLocationOnScreen();
  80         robot.mouseMove(point.x + 20, point.y + 50);
  81         robot.mouseMove(point.x + 30, point.y + 50);
  82         robot.mousePress(InputEvent.BUTTON1_MASK);
  83         robot.mouseRelease(InputEvent.BUTTON1_MASK);
  84     }
  85 }