Skip to content

Commit 880c9e0

Browse files
author
Satyen Subramaniam
committed
8353748: Open source several swing tests batch6
Backport-of: 38f9b3a9738de7896d840fc114a76ced3b77c269
1 parent 6666153 commit 880c9e0

File tree

6 files changed

+501
-0
lines changed

6 files changed

+501
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
/*
25+
* @test
26+
* @bug 4199472
27+
* @summary Tests that node changed for the root of the tree update the
28+
* structure.
29+
* @run main NodeChangedTest
30+
*/
31+
32+
import javax.swing.JTree;
33+
import javax.swing.tree.DefaultMutableTreeNode;
34+
import javax.swing.tree.DefaultTreeModel;
35+
36+
public class NodeChangedTest {
37+
public static void main(String[] args) {
38+
// Create 3 nodes
39+
final DefaultMutableTreeNode root = new DefaultMutableTreeNode("root",
40+
true);
41+
final DefaultMutableTreeNode child = new DefaultMutableTreeNode("child",
42+
true);
43+
final DefaultMutableTreeNode leaf = new DefaultMutableTreeNode("leaf",
44+
false);
45+
root.add(child);
46+
child.add(leaf);
47+
48+
final JTree tree = new JTree(root);
49+
50+
// Change the root node
51+
root.setUserObject("New root");
52+
((DefaultTreeModel) tree.getModel()).nodeChanged(root);
53+
54+
// Check
55+
if (!root.getUserObject().toString().equals("New root")) {
56+
throw new RuntimeException("Failed changing root node for default model.");
57+
}
58+
59+
// Change to large model
60+
tree.setLargeModel(true);
61+
tree.setRowHeight(20);
62+
root.setUserObject("root");
63+
tree.setModel(new DefaultTreeModel(root));
64+
root.setUserObject("New root");
65+
((DefaultTreeModel) tree.getModel()).nodeChanged(root);
66+
67+
// Check again
68+
if (!root.getUserObject().toString().equals("New root")) {
69+
throw new RuntimeException("Failed changing root node for large model.");
70+
}
71+
}
72+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
/*
25+
* @test
26+
* @bug 4118860
27+
* @summary setToggleClickCount/getToggleClickCount have been added.
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4118860
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.Color;
35+
import java.awt.GridLayout;
36+
37+
import javax.swing.JButton;
38+
import javax.swing.JFrame;
39+
import javax.swing.JPanel;
40+
import javax.swing.JTree;
41+
42+
public class bug4118860 {
43+
static final String INSTRUCTIONS = """
44+
Push the "Single Click" button and try expanding/contracting
45+
branch nodes of the tree with one left mouse button click
46+
on the label part of the node (not the icon or handles).
47+
48+
Then push the "Double Click" button and try doing the same using
49+
left mouse button double click. Single click shouldn't cause
50+
expanding/contracting. A double click should now be required
51+
to expand/contract nodes.
52+
53+
If it works then the test PASSES, else the test FAILS.
54+
""";
55+
56+
public static void main(String[] args) throws Exception {
57+
PassFailJFrame.builder()
58+
.title("bug4118860 Test Instructions")
59+
.instructions(INSTRUCTIONS)
60+
.columns(40)
61+
.testUI(bug4118860::createUI)
62+
.build()
63+
.awaitAndCheck();
64+
}
65+
66+
static JFrame createUI() {
67+
JFrame f = new JFrame("ToggleClickCount Test");
68+
JTree tr = new JTree();
69+
JPanel p = new JPanel();
70+
p.setBackground(Color.red);
71+
p.setLayout(new GridLayout(1, 1));
72+
tr.setOpaque(false);
73+
p.add(tr);
74+
f.add(p, BorderLayout.CENTER);
75+
JPanel bp = new JPanel();
76+
JButton bt1 = new JButton("Single Click");
77+
bt1.addActionListener(e -> {
78+
tr.setToggleClickCount(1);
79+
if (tr.getToggleClickCount() != 1) {
80+
throw new RuntimeException("ToggleClickCount doesn't set...");
81+
}
82+
});
83+
JButton bt2 = new JButton("Double Click");
84+
bt2.addActionListener(e -> {
85+
tr.setToggleClickCount(2);
86+
if (tr.getToggleClickCount() != 2) {
87+
throw new RuntimeException("ToggleClickCount doesn't set...");
88+
}
89+
});
90+
bp.setLayout(new GridLayout(1, 2));
91+
bp.add(bt1);
92+
bp.add(bt2);
93+
f.add(bp, BorderLayout.SOUTH);
94+
f.setSize(300, 200);
95+
return f;
96+
}
97+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
/*
25+
* @test
26+
* @bug 4169215
27+
* @summary Accessibility hierarchy JTree node test.
28+
* @run main bug4169215
29+
*/
30+
31+
import javax.accessibility.AccessibleContext;
32+
import javax.swing.JTree;
33+
import javax.swing.tree.DefaultMutableTreeNode;
34+
35+
public class bug4169215 {
36+
public static void main(String[] args) {
37+
// create the tree
38+
DefaultMutableTreeNode root = new DefaultMutableTreeNode("top");
39+
DefaultMutableTreeNode nodeA = new DefaultMutableTreeNode("A");
40+
DefaultMutableTreeNode nodeB = new DefaultMutableTreeNode("B");
41+
root.add(nodeA);
42+
root.add(nodeB);
43+
JTree tree = new JTree(root);
44+
45+
// find the AccessibleContext of the tree
46+
AccessibleContext actree = tree.getAccessibleContext();
47+
48+
// find the AccessibleContext of top node of the tree
49+
AccessibleContext act = actree.getAccessibleChild(0).getAccessibleContext();
50+
51+
// find the AccessibleContext of the first child of the table ->
52+
// the AccessibleContext of nodeA
53+
AccessibleContext accA = act.getAccessibleChild(0).getAccessibleContext();
54+
55+
// find the AccessibleContext of the next sibling of nodeA, by getting
56+
// child+1 of the parent (the table)
57+
AccessibleContext accB = act.getAccessibleChild(
58+
accA.getAccessibleIndexInParent()+1).getAccessibleContext();
59+
60+
// look to see who the sibling is.
61+
if (accB.getAccessibleName().compareTo("B") != 0) {
62+
throw new RuntimeException("Parent node is a sibling instead!");
63+
}
64+
}
65+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
/*
25+
* @test
26+
* @bug 4196987
27+
* @summary Test Metal L&F JTree expander icons transparency.
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4196987
31+
*/
32+
33+
import java.awt.Color;
34+
import java.awt.GridLayout;
35+
36+
import javax.swing.JFrame;
37+
import javax.swing.JPanel;
38+
import javax.swing.JTree;
39+
import javax.swing.UIManager;
40+
41+
public class bug4196987 {
42+
static final String INSTRUCTIONS = """
43+
If the background of tree icons are red, the test PASSES.
44+
Otherwise the test FAILS.
45+
""";
46+
47+
public static void main(String[] args) throws Exception {
48+
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
49+
PassFailJFrame.builder()
50+
.title("bug4196987 Test Instructions")
51+
.instructions(INSTRUCTIONS)
52+
.columns(40)
53+
.testUI(bug4196987::createUI)
54+
.build()
55+
.awaitAndCheck();
56+
}
57+
58+
static JFrame createUI() {
59+
JFrame f = new JFrame("JTree Icon Transparency Test");
60+
JPanel p = new JPanel();
61+
p.setBackground(Color.red);
62+
p.setLayout(new GridLayout(1, 1));
63+
JTree t = new JTree();
64+
t.setOpaque(false);
65+
p.add(t);
66+
f.add(p);
67+
f.setSize(200, 200);
68+
return f;
69+
}
70+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
/*
25+
* @test
26+
* @bug 4270654
27+
* @summary Tests that selection change in JTree does not cause unnecessary
28+
scrolling.
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug4270654
32+
*/
33+
34+
import javax.swing.JFrame;
35+
import javax.swing.JScrollPane;
36+
import javax.swing.JTree;
37+
import javax.swing.tree.DefaultMutableTreeNode;
38+
39+
public class bug4270654 {
40+
static final String INSTRUCTIONS = """
41+
Select the "dan" node and scroll to the right a little using the
42+
scrollbar. Then press down arrow key. If the tree unscrolls back
43+
to the left, the test FAILS. Otherwise, the test PASSES.
44+
""";
45+
46+
public static void main(String[] args) throws Exception {
47+
PassFailJFrame.builder()
48+
.title("bug4270654 Test Instructions")
49+
.instructions(INSTRUCTIONS)
50+
.columns(40)
51+
.testUI(bug4270654::createUI)
52+
.build()
53+
.awaitAndCheck();
54+
}
55+
56+
static JFrame createUI() {
57+
JFrame f = new JFrame("JTree Scroll Back Test");
58+
DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
59+
String[] lev1 = {"foo", "bar", "dan"};
60+
String[][] lev2 = {
61+
{},
62+
{"small", "a nice big node for testing"},
63+
{"xyz", "pqd", "a really really big node for testing"}};
64+
for (int i = 0; i < lev1.length; i++) {
65+
DefaultMutableTreeNode child = new DefaultMutableTreeNode(lev1[i]);
66+
root.add(child);
67+
for (int j = 0; j < lev2[i].length; j++)
68+
child.add(new DefaultMutableTreeNode(lev2[i][j]));
69+
}
70+
final JTree tree = new JTree(root);
71+
tree.expandRow(3);
72+
f.add(new JScrollPane(tree));
73+
f.setSize(200, 200);
74+
return f;
75+
}
76+
}

0 commit comments

Comments
 (0)