Skip to content

Commit f98af0a

Browse files
author
Alexander Zvegintsev
committed
8354701: Open source few JToolTip tests
Reviewed-by: honkar
1 parent e020752 commit f98af0a

File tree

3 files changed

+226
-0
lines changed

3 files changed

+226
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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 4207474 4218495 4375928
27+
* @summary Tests various tooltip issues: HTML tooltips, long tooltip text
28+
* and mnemonic keys displayed in tooltips
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual TooltipTest
32+
*/
33+
34+
import java.awt.FlowLayout;
35+
import java.awt.event.KeyEvent;
36+
import javax.swing.JButton;
37+
import javax.swing.JComponent;
38+
import javax.swing.JPanel;
39+
import javax.swing.UIManager;
40+
41+
public class TooltipTest {
42+
private static final String INSTRUCTIONS = """
43+
1. Move the mouse over the button labeled "Red tip" and let it stay
44+
still in order to test HTML in JToolTip. If the tooltip has some
45+
text which is red then test passes, otherwise it fails (bug 4207474).
46+
47+
2. Move the mouse over the button labeled "Long tip".
48+
If the last letter of the tooltip appears clipped,
49+
then the test fails. If you can see the entire last character,
50+
then the test passes (bug 4218495).
51+
52+
3. Verify that "M" is underlined on the button labeled "Mnemonic"
53+
Move the mouse pointer over the button labeled "Mnemonic" and look
54+
at tooltip when it appears. It should read "hint".
55+
If the above is true test passes else test fails (bug 4375928).
56+
""";
57+
58+
public static void main(String[] args) throws Exception {
59+
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
60+
61+
PassFailJFrame.builder()
62+
.title("TooltipTest Instructions")
63+
.instructions(INSTRUCTIONS)
64+
.columns(40)
65+
.testUI(TooltipTest::createTestUI)
66+
.build()
67+
.awaitAndCheck();
68+
}
69+
70+
private static JComponent createTestUI() {
71+
JPanel panel = new JPanel();
72+
panel.setLayout(new FlowLayout());
73+
74+
JButton b = new JButton("Red tip");
75+
b.setToolTipText("<html><center>Here is some <font color=red>" +
76+
"red</font> text.</center></html>");
77+
panel.add(b);
78+
79+
b = new JButton("Long tip");
80+
b.setToolTipText("Is the last letter clipped?");
81+
panel.add(b);
82+
83+
b = new JButton("Mnemonic");
84+
b.setMnemonic(KeyEvent.VK_M);
85+
b.setToolTipText("hint");
86+
panel.add(b);
87+
88+
return panel;
89+
}
90+
}
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 4225314
27+
* @summary Tests that tooltip is painted properly when it has thick border
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4225314
31+
*/
32+
33+
import java.awt.Color;
34+
import java.awt.FlowLayout;
35+
import javax.swing.JComponent;
36+
import javax.swing.JPanel;
37+
import javax.swing.JToolTip;
38+
import javax.swing.border.LineBorder;
39+
40+
public class bug4225314 {
41+
private static final String INSTRUCTIONS = """
42+
The word "Tooltip" in both tooltips should not be clipped by the
43+
black border and be fully visible for this test to pass.
44+
""";
45+
46+
public static void main(String[] args) throws Exception {
47+
PassFailJFrame.builder()
48+
.title("bug4225314 Instructions")
49+
.instructions(INSTRUCTIONS)
50+
.columns(40)
51+
.testUI(bug4225314::createTestUI)
52+
.build()
53+
.awaitAndCheck();
54+
}
55+
56+
private static JComponent createTestUI() {
57+
JToolTip tt1 = new JToolTip();
58+
tt1.setTipText("Tooltip");
59+
tt1.setBorder(new LineBorder(Color.BLACK, 10));
60+
61+
JToolTip tt2 = new JToolTip();
62+
tt2.setTipText("<html><b><i>Tooltip</i></b></html>");
63+
tt2.setBorder(new LineBorder(Color.BLACK, 10));
64+
65+
JPanel panel = new JPanel();
66+
panel.setLayout(new FlowLayout());
67+
panel.add(tt1);
68+
panel.add(tt2);
69+
70+
return panel;
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2000, 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 4255441
27+
* @summary Tests that tooltip appears inside AWT Frame
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4255441
31+
*/
32+
33+
import java.awt.FlowLayout;
34+
import java.awt.Frame;
35+
import javax.swing.JButton;
36+
37+
public class bug4255441 {
38+
private static final String INSTRUCTIONS = """
39+
Move mouse pointer inside the button.
40+
If a tooltip with "Tooltip text" appears, the test passes.
41+
""";
42+
43+
private static Frame createTestUI() {
44+
Frame fr = new Frame("bug4255441");
45+
fr.setLayout(new FlowLayout());
46+
47+
JButton bt = new JButton("Button");
48+
bt.setToolTipText("Tooltip text");
49+
fr.add(bt);
50+
51+
fr.setSize(200, 200);
52+
return fr;
53+
}
54+
55+
public static void main(String[] argv) throws Exception {
56+
PassFailJFrame.builder()
57+
.title("bug4255441 Instructions")
58+
.instructions(INSTRUCTIONS)
59+
.columns(40)
60+
.testUI(bug4255441::createTestUI)
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
}

0 commit comments

Comments
 (0)