1
1
/*
2
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2013, 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
26
26
* @key headful
27
27
* @bug 7068740
28
28
* @summary JTable wrapped in JLayer can't use PGUP/PGDOWN keys
29
- * @author Vladislav Karnaukhov
30
29
* @run main bug7068740
31
30
*/
32
31
33
- import javax .swing .*;
32
+ import java .awt .Robot ;
33
+ import java .awt .event .KeyEvent ;
34
+ import javax .swing .JComponent ;
35
+ import javax .swing .JFrame ;
36
+ import javax .swing .JLayer ;
37
+ import javax .swing .JScrollPane ;
38
+ import javax .swing .JTable ;
34
39
import javax .swing .plaf .LayerUI ;
35
40
import javax .swing .plaf .metal .MetalLookAndFeel ;
41
+ import javax .swing .SwingUtilities ;
42
+ import javax .swing .UIManager ;
43
+ import javax .swing .UnsupportedLookAndFeelException ;
36
44
import javax .swing .table .DefaultTableModel ;
37
- import java .awt .*;
38
- import java .awt .event .KeyEvent ;
39
- import java .lang .reflect .InvocationTargetException ;
40
45
import java .util .concurrent .atomic .AtomicInteger ;
41
46
42
- public class bug7068740 extends JFrame {
47
+ public class bug7068740 {
43
48
44
49
private static Robot robot = null ;
45
50
private static JTable table = null ;
51
+ private static JFrame frame ;
46
52
47
- bug7068740 () {
48
- super ();
49
- setDefaultCloseOperation (WindowConstants .EXIT_ON_CLOSE );
50
-
51
- DefaultTableModel model = new DefaultTableModel () {
52
- @ Override
53
- public int getRowCount () {
54
- return 20 ;
55
- }
56
-
57
- @ Override
58
- public int getColumnCount () {
59
- return 2 ;
60
- }
53
+ private static void setUp () throws Exception {
54
+ if (robot == null ) {
55
+ robot = new Robot ();
56
+ robot .setAutoDelay (100 );
57
+ }
61
58
59
+ SwingUtilities .invokeAndWait (new Runnable () {
62
60
@ Override
63
- public Object getValueAt (int row , int column ) {
64
- return "(" + row + "," + column + ")" ;
65
- }
66
- };
67
-
68
- table = new JTable (model );
69
- table .setRowSelectionInterval (0 , 0 );
70
- LayerUI <JComponent > layerUI = new LayerUI <>();
71
- JLayer <JComponent > layer = new JLayer <>(table , layerUI );
72
- JScrollPane scrollPane = new JScrollPane (layer );
73
- add (scrollPane );
74
- pack ();
75
- setLocationRelativeTo (null );
76
- }
77
-
78
- private static void setUp () {
79
- try {
80
- if (robot == null ) {
81
- robot = new Robot ();
82
- robot .setAutoDelay (50 );
61
+ public void run () {
62
+ DefaultTableModel model = new DefaultTableModel () {
63
+ @ Override
64
+ public int getRowCount () {
65
+ return 20 ;
66
+ }
67
+
68
+ @ Override
69
+ public int getColumnCount () {
70
+ return 2 ;
71
+ }
72
+
73
+ @ Override
74
+ public Object getValueAt (int row , int column ) {
75
+ return "(" + row + "," + column + ")" ;
76
+ }
77
+ };
78
+
79
+ table = new JTable (model );
80
+ table .setRowSelectionInterval (0 , 0 );
81
+ LayerUI <JComponent > layerUI = new LayerUI <>();
82
+ JLayer <JComponent > layer = new JLayer <>(table , layerUI );
83
+ JScrollPane scrollPane = new JScrollPane (layer );
84
+ frame = new JFrame ();
85
+ frame .add (scrollPane );
86
+ frame .pack ();
87
+ frame .setLocationRelativeTo (null );
88
+ frame .setVisible (true );
83
89
}
84
-
85
- SwingUtilities .invokeAndWait (new Runnable () {
86
- @ Override
87
- public void run () {
88
- bug7068740 test = new bug7068740 ();
89
- test .setVisible (true );
90
- }
91
- });
92
- } catch (InterruptedException e ) {
93
- e .printStackTrace ();
94
- throw new RuntimeException ("Test failed" );
95
- } catch (InvocationTargetException e ) {
96
- e .printStackTrace ();
97
- throw new RuntimeException ("Test failed" );
98
- } catch (AWTException e ) {
99
- e .printStackTrace ();
100
- throw new RuntimeException ("Test failed" );
101
- }
90
+ });
102
91
}
103
92
104
93
private static int getSelectedRow () throws Exception {
@@ -123,6 +112,7 @@ private static void doTest() throws Exception {
123
112
throw new RuntimeException ("Test failed" );
124
113
}
125
114
115
+ robot .delay (1000 );
126
116
robot .keyPress (KeyEvent .VK_PAGE_UP );
127
117
robot .keyRelease (KeyEvent .VK_PAGE_UP );
128
118
robot .waitForIdle ();
@@ -135,10 +125,18 @@ public static void main(String[] args) throws Exception {
135
125
try {
136
126
UIManager .setLookAndFeel (new MetalLookAndFeel ());
137
127
setUp ();
128
+ robot .waitForIdle ();
129
+ robot .delay (1000 );
138
130
doTest ();
139
131
} catch (UnsupportedLookAndFeelException e ) {
140
132
e .printStackTrace ();
141
133
throw new RuntimeException ("Test failed" );
134
+ } finally {
135
+ SwingUtilities .invokeAndWait (() -> {
136
+ if (frame != null ) {
137
+ frame .dispose ();
138
+ }
139
+ });
142
140
}
143
141
}
144
142
}
1 commit comments
openjdk-notifier[bot] commentedon May 1, 2023
Review
Issues