Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTable/7068740/bug7068740.java
38854 views
1
/*
2
* Copyright (c) 2013, 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 7068740
26
@summary JTable wrapped in JLayer can't use PGUP/PGDOWN keys
27
@author Vladislav Karnaukhov
28
@run main bug7068740
29
*/
30
31
import javax.swing.*;
32
import javax.swing.plaf.LayerUI;
33
import javax.swing.plaf.metal.MetalLookAndFeel;
34
import javax.swing.table.DefaultTableModel;
35
import java.awt.*;
36
import java.awt.event.KeyEvent;
37
import java.lang.reflect.InvocationTargetException;
38
import java.util.concurrent.atomic.AtomicInteger;
39
40
public class bug7068740 extends JFrame {
41
42
private static Robot robot = null;
43
private static JTable table = null;
44
45
bug7068740() {
46
super();
47
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
48
49
DefaultTableModel model = new DefaultTableModel() {
50
@Override
51
public int getRowCount() {
52
return 20;
53
}
54
55
@Override
56
public int getColumnCount() {
57
return 2;
58
}
59
60
@Override
61
public Object getValueAt(int row, int column) {
62
return "(" + row + "," + column + ")";
63
}
64
};
65
66
table = new JTable(model);
67
table.setRowSelectionInterval(0, 0);
68
LayerUI<JComponent> layerUI = new LayerUI<>();
69
JLayer<JComponent> layer = new JLayer<>(table, layerUI);
70
JScrollPane scrollPane = new JScrollPane(layer);
71
add(scrollPane);
72
pack();
73
setLocationRelativeTo(null);
74
}
75
76
private static void setUp() {
77
try {
78
if (robot == null) {
79
robot = new Robot();
80
robot.setAutoDelay(50);
81
}
82
83
SwingUtilities.invokeAndWait(new Runnable() {
84
@Override
85
public void run() {
86
bug7068740 test = new bug7068740();
87
test.setVisible(true);
88
}
89
});
90
} catch (InterruptedException e) {
91
e.printStackTrace();
92
throw new RuntimeException("Test failed");
93
} catch (InvocationTargetException e) {
94
e.printStackTrace();
95
throw new RuntimeException("Test failed");
96
} catch (AWTException e) {
97
e.printStackTrace();
98
throw new RuntimeException("Test failed");
99
}
100
}
101
102
private static int getSelectedRow() throws Exception {
103
final AtomicInteger row = new AtomicInteger(-1);
104
SwingUtilities.invokeAndWait(new Runnable() {
105
@Override
106
public void run() {
107
row.set(table.getSelectedRow());
108
}
109
});
110
return row.intValue();
111
}
112
113
private static void doTest() throws Exception {
114
robot.waitForIdle();
115
116
robot.keyPress(KeyEvent.VK_PAGE_DOWN);
117
robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
118
robot.waitForIdle();
119
120
if (getSelectedRow() != 19) {
121
throw new RuntimeException("Test failed");
122
}
123
124
robot.keyPress(KeyEvent.VK_PAGE_UP);
125
robot.keyRelease(KeyEvent.VK_PAGE_UP);
126
robot.waitForIdle();
127
if (getSelectedRow() != 0) {
128
throw new RuntimeException("Test failed");
129
}
130
}
131
132
public static void main(String[] args) throws Exception {
133
try {
134
UIManager.setLookAndFeel(new MetalLookAndFeel());
135
setUp();
136
doTest();
137
} catch (UnsupportedLookAndFeelException e) {
138
e.printStackTrace();
139
throw new RuntimeException("Test failed");
140
}
141
}
142
}
143
144