Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 5699024

Browse files
author
Pankaj Bansal
committedJul 1, 2020
8197560: test javax/swing/JTree/8003400/Test8003400.java fails
Reviewed-by: serb, psadhukhan
1 parent 921155d commit 5699024

File tree

2 files changed

+83
-44
lines changed

2 files changed

+83
-44
lines changed
 

‎test/jdk/ProblemList.txt

-1
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,6 @@ javax/swing/Popup/TaskbarPositionTest.java 8065097 macosx-all,linux-all
820820
javax/swing/JEditorPane/6917744/bug6917744.java 8213124 macosx-all
821821
javax/swing/JTable/6263446/bug6263446.java 8169959 macosx-all
822822
javax/swing/JTree/6263446/bug6263446.java 8213125 macosx-all
823-
javax/swing/JTree/8003400/Test8003400.java 8197560 macosx-all,linux-all
824823
javax/swing/ToolTipManager/Test6256140.java 8233560 macosx-all
825824
javax/swing/text/View/8014863/bug8014863.java 8233561 macosx-all
826825
javax/swing/text/StyledEditorKit/4506788/bug4506788.java 8233562 macosx-all

‎test/jdk/javax/swing/JTree/8003400/Test8003400.java

+83-43
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@
2727
* @bug 8003400
2828
* @summary Tests that JTree shows the last row
2929
* @author Sergey Malenkov
30-
* @library /lib/client
31-
* @build ExtendedRobot
3230
* @run main/othervm Test8003400
3331
* @run main/othervm Test8003400 reverse
34-
* @run main/othervm Test8003400 system
35-
* @run main/othervm Test8003400 system reverse
3632
*/
3733

34+
import java.awt.Component;
35+
import java.awt.event.InputEvent;
36+
import java.awt.Point;
3837
import java.awt.Rectangle;
3938
import java.awt.Robot;
4039
import java.awt.event.KeyEvent;
@@ -53,59 +52,100 @@ public class Test8003400 {
5352
private static final String TITLE = "Test JTree with a large model";
5453
private static List<String> OBJECTS = Arrays.asList(TITLE, "x", "y", "z");
5554
private static JScrollPane pane;
55+
private static JFrame frame;
56+
private static JTree tree;
57+
private static Point point;
58+
private static Rectangle rect;
59+
60+
public static void blockTillDisplayed(Component comp) {
61+
Point p = null;
62+
while (p == null) {
63+
try {
64+
p = comp.getLocationOnScreen();
65+
} catch (IllegalStateException e) {
66+
try {
67+
Thread.sleep(500);
68+
} catch (InterruptedException ie) {
69+
}
70+
}
71+
}
72+
}
5673

5774
public static void main(String[] args) throws Exception {
5875
for (String arg : args) {
5976
if (arg.equals("reverse")) {
6077
Collections.reverse(OBJECTS);
6178
}
62-
if (arg.equals("system")) {
63-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
64-
}
6579
}
66-
SwingUtilities.invokeAndWait(new Runnable() {
67-
public void run() {
68-
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
80+
UIManager.LookAndFeelInfo infos[] = UIManager.getInstalledLookAndFeels();
81+
for (UIManager.LookAndFeelInfo info : infos) {
82+
UIManager.setLookAndFeel(info.getClassName());
83+
System.out.println(info.getClassName());
84+
try {
85+
SwingUtilities.invokeAndWait(new Runnable() {
86+
public void run() {
87+
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
6988

70-
JTree tree = new JTree(root);
71-
tree.setLargeModel(true);
72-
tree.setRowHeight(16);
89+
tree = new JTree(root);
90+
tree.setLargeModel(true);
91+
tree.setRowHeight(16);
7392

74-
JFrame frame = new JFrame(TITLE);
75-
frame.add(pane = new JScrollPane(tree));
76-
frame.setSize(200, 100);
77-
frame.setLocationRelativeTo(null);
78-
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
79-
frame.setVisible(true);
93+
frame = new JFrame(TITLE);
94+
frame.add(pane = new JScrollPane(tree));
95+
frame.setSize(200, 100);
96+
frame.setAlwaysOnTop(true);
97+
frame.setLocationRelativeTo(null);
98+
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
99+
frame.setVisible(true);
80100

81-
for (String object : OBJECTS) {
82-
root.add(new DefaultMutableTreeNode(object));
83-
}
84-
tree.expandRow(0);
85-
}
86-
});
101+
for (String object : OBJECTS) {
102+
root.add(new DefaultMutableTreeNode(object));
103+
}
104+
tree.expandRow(0);
105+
}
106+
});
87107

88-
ExtendedRobot robot = new ExtendedRobot();
89-
robot.waitForIdle(500);
90-
robot.keyPress(KeyEvent.VK_END);
91-
robot.waitForIdle(500);
92-
robot.keyRelease(KeyEvent.VK_END);
93-
robot.waitForIdle();
108+
blockTillDisplayed(frame);
94109

95-
SwingUtilities.invokeAndWait(new Runnable() {
96-
public void run() {
97-
JTree tree = (JTree) pane.getViewport().getView();
98-
Rectangle inner = tree.getRowBounds(tree.getRowCount() - 1);
99-
Rectangle outer = SwingUtilities.convertRectangle(tree, inner, pane);
100-
outer.y += tree.getRowHeight() - 1 - pane.getVerticalScrollBar().getHeight();
101-
// error reporting only for automatic testing
102-
if (null != System.getProperty("test.src", null)) {
103-
SwingUtilities.getWindowAncestor(pane).dispose();
104-
if (outer.y != 0) {
105-
throw new Error("TEST FAILED: " + outer.y);
110+
Robot robot = new Robot();
111+
robot.setAutoDelay(100);
112+
SwingUtilities.invokeAndWait(() -> {
113+
point = tree.getLocationOnScreen();
114+
rect = tree.getBounds();
115+
});
116+
robot.waitForIdle();
117+
robot.delay(500);
118+
robot.mouseMove(point.x + rect.width / 2, point.y + rect.height / 3);
119+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
120+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
121+
122+
robot.waitForIdle();
123+
robot.delay(1000);
124+
robot.keyPress(KeyEvent.VK_END);
125+
robot.keyRelease(KeyEvent.VK_END);
126+
robot.waitForIdle();
127+
robot.delay(1000);
128+
129+
SwingUtilities.invokeAndWait(new Runnable() {
130+
public void run() {
131+
JTree tree = (JTree) pane.getViewport().getView();
132+
Rectangle inner = tree.getRowBounds(tree.getRowCount() - 1);
133+
Rectangle outer = SwingUtilities.convertRectangle(tree, inner, pane);
134+
int heightDifference = outer.y + tree.getRowHeight() - pane.getVerticalScrollBar().getHeight();
135+
// error reporting only for automatic testing
136+
if (null != System.getProperty("test.src", null)) {
137+
frame.dispose();
138+
if (heightDifference > 3) {
139+
throw new Error("TEST FAILED: " + heightDifference);
140+
}
141+
}
106142
}
143+
});
144+
} finally {
145+
if (frame != null) {
146+
SwingUtilities.invokeAndWait(frame::dispose);
107147
}
108148
}
109-
});
149+
}
110150
}
111151
}

0 commit comments

Comments
 (0)
This repository has been archived.