author | duke |
Wed, 05 Jul 2017 17:52:05 +0200 (2017-07-05) | |
changeset 10620 | 9df40a1578ef |
parent 6374 | e214162c907e |
child 28071 | 3acb75b8df45 |
permissions | -rw-r--r-- |
5590
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
1 |
/* |
6374
e214162c907e
6982137: Rebranding pass 2 - missed copyright changes
ohair
parents:
5590
diff
changeset
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
5590
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
4 |
* |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
8 |
* |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
13 |
* accompanied this code). |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
14 |
* |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
18 |
* |
6374
e214162c907e
6982137: Rebranding pass 2 - missed copyright changes
ohair
parents:
5590
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e214162c907e
6982137: Rebranding pass 2 - missed copyright changes
ohair
parents:
5590
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e214162c907e
6982137: Rebranding pass 2 - missed copyright changes
ohair
parents:
5590
diff
changeset
|
21 |
* questions. |
5590
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
22 |
*/ |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
23 |
|
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
24 |
/* @test |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
25 |
@bug 6884066 |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
26 |
@summary JTableHeader listens mouse in disabled state and doesn't work when not attached to a table |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
27 |
@author Alexander Potochkin |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
28 |
@run main bug6884066 |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
29 |
*/ |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
30 |
|
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
31 |
import sun.awt.SunToolkit; |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
32 |
|
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
33 |
import javax.swing.*; |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
34 |
import javax.swing.table.JTableHeader; |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
35 |
import javax.swing.table.TableColumnModel; |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
36 |
import javax.swing.table.TableColumn; |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
37 |
import java.awt.*; |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
38 |
import java.awt.event.InputEvent; |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
39 |
|
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
40 |
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel; |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
41 |
|
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
42 |
public class bug6884066 { |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
43 |
private static JTableHeader header; |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
44 |
|
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
45 |
public static void main(String[] args) throws Exception { |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
46 |
|
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
47 |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
48 |
|
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
49 |
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
50 |
Robot robot = new Robot(); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
51 |
robot.setAutoDelay(20); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
52 |
SwingUtilities.invokeAndWait(new Runnable() { |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
53 |
public void run() { |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
54 |
// just to quickly grab a column model |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
55 |
JTable table = new JTable(10, 5); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
56 |
header = new JTableHeader(table.getColumnModel()); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
57 |
checkColumn(0, "A"); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
58 |
JFrame frame = new JFrame("standalone header"); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
59 |
frame.add(header); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
60 |
frame.pack(); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
61 |
frame.setVisible(true); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
62 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
63 |
} |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
64 |
}); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
65 |
toolkit.realSync(); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
66 |
Point point = header.getLocationOnScreen(); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
67 |
robot.mouseMove(point.x + 3, point.y + 3); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
68 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
69 |
for (int i = 0; i < header.getWidth() - 3; i++) { |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
70 |
robot.mouseMove(point.x + i, point.y + 3); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
71 |
} |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
72 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
73 |
SwingUtilities.invokeAndWait(new Runnable() { |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
74 |
public void run() { |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
75 |
TableColumnModel model = header.getColumnModel(); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
76 |
checkColumn(model.getColumnCount() - 1, "A"); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
77 |
} |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
78 |
}); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
79 |
} |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
80 |
|
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
81 |
private static void checkColumn(int index, String str) { |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
82 |
TableColumnModel model = header.getColumnModel(); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
83 |
Object value = model.getColumn(index).getHeaderValue(); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
84 |
if (!str.equals(value)) { |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
85 |
throw new RuntimeException("Unexpected header's value; " + |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
86 |
"index = " + index + " value = " + value); |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
87 |
} |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
88 |
} |
3ec077d7e893
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
alexp
parents:
diff
changeset
|
89 |
} |