|
| 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 | +} |
0 commit comments