|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
23 | 23 |
|
24 | 24 | /*
|
25 | 25 | @test
|
26 |
| - @key headful |
| 26 | + @key headful |
27 | 27 | @bug 6884066
|
28 | 28 | @summary JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
|
29 |
| - @author Alexander Potochkin |
30 | 29 | @run main bug6884066
|
31 | 30 | */
|
32 | 31 |
|
33 |
| -import javax.swing.*; |
| 32 | +import java.awt.event.InputEvent; |
| 33 | +import java.awt.Point; |
| 34 | +import java.awt.Robot; |
| 35 | +import javax.swing.JFrame; |
| 36 | +import javax.swing.JTable; |
34 | 37 | import javax.swing.table.JTableHeader;
|
35 | 38 | import javax.swing.table.TableColumnModel;
|
36 | 39 | import javax.swing.table.TableColumn;
|
37 |
| -import java.awt.*; |
38 |
| -import java.awt.event.InputEvent; |
| 40 | +import javax.swing.SwingUtilities; |
| 41 | +import javax.swing.UIManager; |
39 | 42 |
|
40 | 43 | public class bug6884066 {
|
| 44 | + private static JFrame frame; |
41 | 45 | private static JTableHeader header;
|
| 46 | + private static volatile Point point; |
42 | 47 |
|
43 | 48 | public static void main(String[] args) throws Exception {
|
| 49 | + try { |
| 50 | + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
44 | 51 |
|
45 |
| - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
46 |
| - |
47 |
| - Robot robot = new Robot(); |
48 |
| - robot.setAutoDelay(20); |
49 |
| - SwingUtilities.invokeAndWait(new Runnable() { |
50 |
| - public void run() { |
51 |
| - // just to quickly grab a column model |
52 |
| - JTable table = new JTable(10, 5); |
53 |
| - header = new JTableHeader(table.getColumnModel()); |
54 |
| - checkColumn(0, "A"); |
55 |
| - JFrame frame = new JFrame("standalone header"); |
56 |
| - frame.add(header); |
57 |
| - frame.pack(); |
58 |
| - frame.setVisible(true); |
59 |
| - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 52 | + Robot robot = new Robot(); |
| 53 | + robot.setAutoDelay(100); |
| 54 | + SwingUtilities.invokeAndWait(new Runnable() { |
| 55 | + public void run() { |
| 56 | + // just to quickly grab a column model |
| 57 | + JTable table = new JTable(10, 5); |
| 58 | + header = new JTableHeader(table.getColumnModel()); |
| 59 | + checkColumn(0, "A"); |
| 60 | + frame = new JFrame("standalone header"); |
| 61 | + frame.add(header); |
| 62 | + frame.pack(); |
| 63 | + frame.setLocationRelativeTo(null); |
| 64 | + frame.setVisible(true); |
| 65 | + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 66 | + } |
| 67 | + }); |
| 68 | + robot.waitForIdle(); |
| 69 | + robot.delay(1000); |
| 70 | + SwingUtilities.invokeAndWait(() -> { |
| 71 | + point = header.getLocationOnScreen(); |
| 72 | + }); |
| 73 | + robot.mouseMove(point.x + 3, point.y + 3); |
| 74 | + robot.waitForIdle(); |
| 75 | + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); |
| 76 | + for (int i = 0; i < header.getWidth() - 3; i++) { |
| 77 | + robot.mouseMove(point.x + i, point.y + 3); |
60 | 78 | }
|
61 |
| - }); |
62 |
| - robot.waitForIdle(); |
63 |
| - Point point = header.getLocationOnScreen(); |
64 |
| - robot.mouseMove(point.x + 3, point.y + 3); |
65 |
| - robot.mousePress(InputEvent.BUTTON1_MASK); |
66 |
| - for (int i = 0; i < header.getWidth() - 3; i++) { |
67 |
| - robot.mouseMove(point.x + i, point.y + 3); |
| 79 | + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); |
| 80 | + robot.waitForIdle(); |
| 81 | + SwingUtilities.invokeAndWait(new Runnable() { |
| 82 | + public void run() { |
| 83 | + TableColumnModel model = header.getColumnModel(); |
| 84 | + checkColumn(model.getColumnCount() - 1, "A"); |
| 85 | + } |
| 86 | + }); |
| 87 | + } finally { |
| 88 | + SwingUtilities.invokeAndWait(() -> { |
| 89 | + if (frame != null) { |
| 90 | + frame.dispose(); |
| 91 | + } |
| 92 | + }); |
68 | 93 | }
|
69 |
| - robot.mouseRelease(InputEvent.BUTTON1_MASK); |
70 |
| - SwingUtilities.invokeAndWait(new Runnable() { |
71 |
| - public void run() { |
72 |
| - TableColumnModel model = header.getColumnModel(); |
73 |
| - checkColumn(model.getColumnCount() - 1, "A"); |
74 |
| - } |
75 |
| - }); |
76 | 94 | }
|
77 | 95 |
|
78 | 96 | private static void checkColumn(int index, String str) {
|
|
0 commit comments