Skip to content

Commit a8d5a40

Browse files
author
Satyen Subramaniam
committed
8353201: Open source Swing Tooltip tests - Set 2
Backport-of: e17c3994b8392357b0aacea0bae6b354a2cc90a5
1 parent 1275f32 commit a8d5a40

File tree

3 files changed

+282
-0
lines changed

3 files changed

+282
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2003, 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 4250178
27+
* @summary Tooltip in incorrect location on ToolBar
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4250178
31+
*/
32+
33+
import javax.swing.JButton;
34+
import javax.swing.JFrame;
35+
import javax.swing.ToolTipManager;
36+
37+
public class bug4250178 {
38+
private static final String INSTRUCTIONS = """
39+
Click somewhere in the test UI frame to make it focused.
40+
Move mouse to the bottom right corner of the button in this frame
41+
and wait until tooltip appears.
42+
43+
If the tooltip fits into the frame OR partially covered by the mouse
44+
cursor then test fails. Otherwise test passes.
45+
""";
46+
47+
public static void main(String[] args) throws Exception {
48+
PassFailJFrame.builder()
49+
.title("Test Instructions")
50+
.instructions(INSTRUCTIONS)
51+
.columns(35)
52+
.testUI(bug4250178::createAndShowUI)
53+
.build()
54+
.awaitAndCheck();
55+
}
56+
57+
private static JFrame createAndShowUI() {
58+
JFrame fr = new JFrame("bug4250178");
59+
JButton button = new JButton("Button");
60+
button.setToolTipText("ToolTip");
61+
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(true);
62+
fr.add(button);
63+
fr.setSize(250, 100);
64+
return fr;
65+
}
66+
}
Lines changed: 64 additions & 0 deletions
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 4294808
27+
* @summary Tooltip blinking.
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4294808
31+
*/
32+
33+
import java.awt.Dimension;
34+
import javax.swing.JButton;
35+
import javax.swing.JComponent;
36+
37+
public class bug4294808 {
38+
private static final String INSTRUCTIONS = """
39+
Move mouse cursor to the button named "Tooltip Button"
40+
at the bottom of the instruction window and wait until
41+
tooltip has appeared.
42+
43+
If tooltip appears and eventually disappears without
44+
rapid blinking then press PASS else FAIL.
45+
""";
46+
47+
48+
public static void main(String[] args) throws Exception {
49+
PassFailJFrame.builder()
50+
.title("bug4294808 Test Instructions")
51+
.instructions(INSTRUCTIONS)
52+
.columns(35)
53+
.splitUIBottom(bug4294808::createAndShowUI)
54+
.build()
55+
.awaitAndCheck();
56+
}
57+
58+
private static JComponent createAndShowUI() {
59+
JButton bt = new JButton("Tooltip Button");
60+
bt.setToolTipText("Long tooltip text here");
61+
bt.setPreferredSize(new Dimension(200, 60));
62+
return bt;
63+
}
64+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* Copyright (c) 2006, 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 4148057 6178004
27+
* @summary REGRESSION: setToolTipText does not work if the
28+
* component is not focused
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug6178004
32+
*/
33+
34+
import java.awt.Point;
35+
import java.awt.Window;
36+
import java.awt.event.MouseEvent;
37+
import java.util.List;
38+
import javax.swing.ButtonGroup;
39+
import javax.swing.JButton;
40+
import javax.swing.JCheckBoxMenuItem;
41+
import javax.swing.JFrame;
42+
import javax.swing.JMenu;
43+
import javax.swing.JMenuBar;
44+
import javax.swing.LookAndFeel;
45+
import javax.swing.SwingUtilities;
46+
import javax.swing.ToolTipManager;
47+
import javax.swing.UIManager;
48+
49+
public class bug6178004 {
50+
private static JFrame frame1;
51+
private static JFrame frame2;
52+
private static final int SIZE = 300;
53+
54+
private static final String INSTRUCTIONS = """
55+
You can change Look And Feel using the menu "Change LaF".
56+
57+
Make sure that Frame2 or instruction window is active.
58+
Move mouse over the button inside "Frame 1".
59+
If tooltip is NOT shown or Frame 1 jumped on top of
60+
the Frame2, press FAIL.
61+
62+
For Metal/Windows LaF:
63+
Tooltips are shown only if one of the frames (or the instruction
64+
window) is active. To test it click on any other application to
65+
make frames and instruction window inactive and then verify that
66+
tooltips are not shown any more.
67+
68+
For Motif/GTK/Nimbus/Aqua LaF:
69+
Tooltips should be shown for all frames irrespective of whether
70+
the application is active or inactive.
71+
72+
Note: Tooltip for Frame1 is always shown at the top-left corner.
73+
Tooltips could be shown partly covered by another frame.
74+
75+
If above is true press PASS else FAIL.
76+
""";
77+
78+
public static void main(String[] args) throws Exception {
79+
PassFailJFrame.builder()
80+
.title("bug6178004 Test Instructions")
81+
.instructions(INSTRUCTIONS)
82+
.testTimeOut(10)
83+
.columns(40)
84+
.testUI(createAndShowUI())
85+
.positionTestUI(bug6178004::positionTestWindows)
86+
.build()
87+
.awaitAndCheck();
88+
}
89+
90+
private static List<Window> createAndShowUI() {
91+
ToolTipManager.sharedInstance().setInitialDelay(0);
92+
93+
frame1 = new JFrame("bug6178004 Frame1");
94+
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
95+
JButton button = new JButton("Test") {
96+
public Point getToolTipLocation(MouseEvent event) {
97+
return new Point(10, 10);
98+
}
99+
};
100+
button.setToolTipText("Tooltip-1");
101+
frame1.add(button);
102+
frame1.setSize(SIZE, SIZE);
103+
104+
frame2 = new JFrame("bug6178004 Frame2");
105+
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
106+
JButton button2 = new JButton("Click me") ;
107+
button2.setToolTipText("Tooltip-2");
108+
frame2.add(button2);
109+
frame2.setSize(SIZE, SIZE);
110+
111+
JMenuBar bar = new JMenuBar();
112+
JMenu lafMenu = new JMenu("Change LaF");
113+
ButtonGroup lafGroup = new ButtonGroup();
114+
115+
LookAndFeel currentLaf = UIManager.getLookAndFeel();
116+
UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
117+
for (final UIManager.LookAndFeelInfo lafInfo : lafs) {
118+
JCheckBoxMenuItem lafItem = new JCheckBoxMenuItem(lafInfo.getName());
119+
lafItem.addActionListener(e -> setLaF(lafInfo.getClassName()));
120+
if (lafInfo.getClassName().equals(currentLaf.getClass().getName())) {
121+
lafItem.setSelected(true);
122+
}
123+
124+
lafGroup.add(lafItem);
125+
lafMenu.add(lafItem);
126+
}
127+
128+
bar.add(lafMenu);
129+
frame2.setJMenuBar(bar);
130+
return List.of(frame1, frame2);
131+
}
132+
133+
private static void setLaF(String laf) {
134+
try {
135+
UIManager.setLookAndFeel(laf);
136+
SwingUtilities.updateComponentTreeUI(frame1);
137+
SwingUtilities.updateComponentTreeUI(frame2);
138+
} catch (Exception e) {
139+
e.printStackTrace();
140+
}
141+
}
142+
143+
// custom window layout required for this test
144+
private static void positionTestWindows(List<? extends Window> testWindows,
145+
PassFailJFrame.InstructionUI instructionUI) {
146+
int gap = 5;
147+
int x = instructionUI.getLocation().x + instructionUI.getSize().width + gap;
148+
// the two test frames need to overlap for this test
149+
testWindows.get(0).setLocation(x, instructionUI.getLocation().y);
150+
testWindows.get(1).setLocation((x + SIZE / 2), instructionUI.getLocation().y);
151+
}
152+
}

0 commit comments

Comments
 (0)