Skip to content

Commit 8abf13e

Browse files
committed
8315952: Open source several Swing JToolbar JTooltip JTree tests
Backport-of: d2b2f6759f7b9eb6df8eaa84b88e064c636b24a8
1 parent a01f024 commit 8abf13e

File tree

5 files changed

+262
-0
lines changed

5 files changed

+262
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2000, 2023, 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 4368050
26+
* @summary Default toolbar layout manager should be serializable.
27+
* @run main bug4368050
28+
*/
29+
30+
import java.io.ByteArrayInputStream;
31+
import java.io.ByteArrayOutputStream;
32+
import java.io.ObjectInputStream;
33+
import java.io.ObjectOutputStream;
34+
35+
import javax.swing.JToolBar;
36+
37+
public class bug4368050 {
38+
public static void main(String[] args) throws Exception {
39+
JToolBar toolBar = new JToolBar();
40+
41+
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
42+
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
43+
oos.writeObject(toolBar);
44+
byte[] buf = baos.toByteArray();
45+
try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
46+
ObjectInputStream ois = new ObjectInputStream(bais)) {
47+
ois.readObject();
48+
}
49+
}
50+
}
51+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2001, 2023, 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 4465534
26+
* @summary Tests adding borderless button to a toolbar
27+
* @run main bug4465534
28+
*/
29+
30+
import javax.swing.JButton;
31+
import javax.swing.JToolBar;
32+
import javax.swing.SwingUtilities;
33+
34+
public class bug4465534 {
35+
public static void main(String[] args) throws Exception {
36+
SwingUtilities.invokeAndWait(() -> {
37+
JToolBar toolbar = new JToolBar();
38+
JButton button = new JButton("text");
39+
button.setBorder(null);
40+
toolbar.add(button);
41+
});
42+
}
43+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2003, 2023, 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 4700351
26+
* @summary Checks if JToolBar keeps orientation when dragged off
27+
* @key headful
28+
* @run main bug4700351
29+
*/
30+
31+
import javax.swing.JFrame;
32+
import javax.swing.JToolBar;
33+
import javax.swing.SwingUtilities;
34+
import javax.swing.plaf.basic.BasicToolBarUI;
35+
36+
public class bug4700351 {
37+
static JFrame fr;
38+
39+
public static void main(String[] args) throws Exception {
40+
try {
41+
SwingUtilities.invokeAndWait(() -> {
42+
fr = new JFrame("bug4700351");
43+
JToolBar tb = new JToolBar();
44+
tb.setOrientation(JToolBar.VERTICAL);
45+
fr.add(tb);
46+
BasicToolBarUI ui = (javax.swing.plaf.basic.BasicToolBarUI) tb.getUI();
47+
if (!ui.isFloating()) {
48+
ui.setFloatingLocation(100, 100);
49+
ui.setFloating(true, tb.getLocation());
50+
}
51+
if (tb.getOrientation() != JToolBar.VERTICAL) {
52+
throw new RuntimeException("Error: toolbar's orientation " +
53+
"has changed");
54+
}
55+
});
56+
} finally {
57+
SwingUtilities.invokeAndWait(() -> {
58+
if (fr != null) {
59+
fr.dispose();
60+
}
61+
});
62+
}
63+
}
64+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 1999, 2023, 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 4107843
26+
* @summary ToolTipText for JTabbedPane.
27+
* @run main bug4107843
28+
*/
29+
30+
import javax.swing.JButton;
31+
import javax.swing.JTabbedPane;
32+
import javax.swing.SwingUtilities;
33+
34+
public class bug4107843 {
35+
public static void main(String[] args) throws Exception {
36+
SwingUtilities.invokeAndWait(() -> {
37+
JTabbedPane tp = new JTabbedPane();
38+
tp.add("First", new JButton("Button1"));
39+
tp.add("Second", new JButton("Button2"));
40+
tp.setToolTipTextAt(0, "first button");
41+
if (!tp.getToolTipTextAt(0).equals("first button")) {
42+
throw new RuntimeException("ToolTipText isn't set " +
43+
"as expected...");
44+
}
45+
tp.setToolTipTextAt(1, "second button");
46+
if (!tp.getToolTipTextAt(1).equals("second button")) {
47+
throw new RuntimeException("ToolTipText isn't set " +
48+
"as expected...");
49+
}
50+
});
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 1999, 2023, 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 4161685
26+
* @summary JTree now has the public methods setAnchorSelectionPath,
27+
* getAnchorSelectionPath, setLeadSelectionPath.
28+
* @run main bug4161685
29+
*/
30+
31+
import javax.swing.JTree;
32+
import javax.swing.SwingUtilities;
33+
import javax.swing.tree.TreePath;
34+
35+
public class bug4161685 {
36+
public static void main(String[] args) throws Exception {
37+
SwingUtilities.invokeAndWait(() -> {
38+
JTree tr = new JTree();
39+
TreePath tp = tr.getPathForRow(2);
40+
tr.setAnchorSelectionPath(tp);
41+
if (tr.getAnchorSelectionPath() != tp) {
42+
throw new RuntimeException("AnchorSelectionPath isn't " +
43+
"set correctly...");
44+
}
45+
tr.setLeadSelectionPath(tp);
46+
if (tr.getLeadSelectionPath() != tp) {
47+
throw new RuntimeException("LeadSelectionPath isn't " +
48+
"set correctly...");
49+
}
50+
});
51+
}
52+
}

0 commit comments

Comments
 (0)