Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions test/jdk/javax/swing/JTree/NodeChangedTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 4199472
* @summary Tests that node changed for the root of the tree update the
* structure.
* @run main NodeChangedTest
*/

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

public class NodeChangedTest {
public static void main(String[] args) {
// Create 3 nodes
final DefaultMutableTreeNode root = new DefaultMutableTreeNode("root",
true);
final DefaultMutableTreeNode child = new DefaultMutableTreeNode("child",
true);
final DefaultMutableTreeNode leaf = new DefaultMutableTreeNode("leaf",
false);
root.add(child);
child.add(leaf);

final JTree tree = new JTree(root);

// Change the root node
root.setUserObject("New root");
((DefaultTreeModel) tree.getModel()).nodeChanged(root);

// Check
if (!root.getUserObject().toString().equals("New root")) {
throw new RuntimeException("Failed changing root node for default model.");
}

// Change to large model
tree.setLargeModel(true);
tree.setRowHeight(20);
root.setUserObject("root");
tree.setModel(new DefaultTreeModel(root));
root.setUserObject("New root");
((DefaultTreeModel) tree.getModel()).nodeChanged(root);

// Check again
if (!root.getUserObject().toString().equals("New root")) {
throw new RuntimeException("Failed changing root node for large model.");
}
}
}
97 changes: 97 additions & 0 deletions test/jdk/javax/swing/JTree/bug4118860.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 4118860
* @summary setToggleClickCount/getToggleClickCount have been added.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4118860
*/

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTree;

public class bug4118860 {
static final String INSTRUCTIONS = """
Push the "Single Click" button and try expanding/contracting
branch nodes of the tree with one left mouse button click
on the label part of the node (not the icon or handles).

Then push the "Double Click" button and try doing the same using
left mouse button double click. Single click shouldn't cause
expanding/contracting. A double click should now be required
to expand/contract nodes.

If it works then the test PASSES, else the test FAILS.
""";

public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.title("bug4118860 Test Instructions")
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(bug4118860::createUI)
.build()
.awaitAndCheck();
}

static JFrame createUI() {
JFrame f = new JFrame("ToggleClickCount Test");
JTree tr = new JTree();
JPanel p = new JPanel();
p.setBackground(Color.red);
p.setLayout(new GridLayout(1, 1));
tr.setOpaque(false);
p.add(tr);
f.add(p, BorderLayout.CENTER);
JPanel bp = new JPanel();
JButton bt1 = new JButton("Single Click");
bt1.addActionListener(e -> {
tr.setToggleClickCount(1);
if (tr.getToggleClickCount() != 1) {
throw new RuntimeException("ToggleClickCount doesn't set...");
}
});
JButton bt2 = new JButton("Double Click");
bt2.addActionListener(e -> {
tr.setToggleClickCount(2);
if (tr.getToggleClickCount() != 2) {
throw new RuntimeException("ToggleClickCount doesn't set...");
}
});
bp.setLayout(new GridLayout(1, 2));
bp.add(bt1);
bp.add(bt2);
f.add(bp, BorderLayout.SOUTH);
f.setSize(300, 200);
return f;
}
}
65 changes: 65 additions & 0 deletions test/jdk/javax/swing/JTree/bug4169215.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 4169215
* @summary Accessibility hierarchy JTree node test.
* @run main bug4169215
*/

import javax.accessibility.AccessibleContext;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

public class bug4169215 {
public static void main(String[] args) {
// create the tree
DefaultMutableTreeNode root = new DefaultMutableTreeNode("top");
DefaultMutableTreeNode nodeA = new DefaultMutableTreeNode("A");
DefaultMutableTreeNode nodeB = new DefaultMutableTreeNode("B");
root.add(nodeA);
root.add(nodeB);
JTree tree = new JTree(root);

// find the AccessibleContext of the tree
AccessibleContext actree = tree.getAccessibleContext();

// find the AccessibleContext of top node of the tree
AccessibleContext act = actree.getAccessibleChild(0).getAccessibleContext();

// find the AccessibleContext of the first child of the table ->
// the AccessibleContext of nodeA
AccessibleContext accA = act.getAccessibleChild(0).getAccessibleContext();

// find the AccessibleContext of the next sibling of nodeA, by getting
// child+1 of the parent (the table)
AccessibleContext accB = act.getAccessibleChild(
accA.getAccessibleIndexInParent()+1).getAccessibleContext();

// look to see who the sibling is.
if (accB.getAccessibleName().compareTo("B") != 0) {
throw new RuntimeException("Parent node is a sibling instead!");
}
}
}
70 changes: 70 additions & 0 deletions test/jdk/javax/swing/JTree/bug4196987.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 4196987
* @summary Test Metal L&F JTree expander icons transparency.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4196987
*/

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.UIManager;

public class bug4196987 {
static final String INSTRUCTIONS = """
If the background of tree icons are red, the test PASSES.
Otherwise the test FAILS.
""";

public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
PassFailJFrame.builder()
.title("bug4196987 Test Instructions")
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(bug4196987::createUI)
.build()
.awaitAndCheck();
}

static JFrame createUI() {
JFrame f = new JFrame("JTree Icon Transparency Test");
JPanel p = new JPanel();
p.setBackground(Color.red);
p.setLayout(new GridLayout(1, 1));
JTree t = new JTree();
t.setOpaque(false);
p.add(t);
f.add(p);
f.setSize(200, 200);
return f;
}
}
76 changes: 76 additions & 0 deletions test/jdk/javax/swing/JTree/bug4270654.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 4270654
* @summary Tests that selection change in JTree does not cause unnecessary
scrolling.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4270654
*/

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

public class bug4270654 {
static final String INSTRUCTIONS = """
Select the "dan" node and scroll to the right a little using the
scrollbar. Then press down arrow key. If the tree unscrolls back
to the left, the test FAILS. Otherwise, the test PASSES.
""";

public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.title("bug4270654 Test Instructions")
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(bug4270654::createUI)
.build()
.awaitAndCheck();
}

static JFrame createUI() {
JFrame f = new JFrame("JTree Scroll Back Test");
DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
String[] lev1 = {"foo", "bar", "dan"};
String[][] lev2 = {
{},
{"small", "a nice big node for testing"},
{"xyz", "pqd", "a really really big node for testing"}};
for (int i = 0; i < lev1.length; i++) {
DefaultMutableTreeNode child = new DefaultMutableTreeNode(lev1[i]);
root.add(child);
for (int j = 0; j < lev2[i].length; j++)
child.add(new DefaultMutableTreeNode(lev2[i][j]));
}
final JTree tree = new JTree(root);
tree.expandRow(3);
f.add(new JScrollPane(tree));
f.setSize(200, 200);
return f;
}
}
Loading