Reputation: 52478
On OS X, an "alwaysOnTop" JFrame made using Java's Swing GUI framework sporadically flicks tooltips away almost immediately after showing them.
This problem is almost too obscure to explain and yet can be reproduced with little code. If you use Java on Mac, the best I can do is ask you to try this self-contained code sample:
import javax.swing.*;
public class ScratchSpace {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("Test");
// setting alwaysOnTop to false makes the problem go away
frame.setAlwaysOnTop(true);
JPanel contentPane = new JPanel();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.LINE_AXIS));
JLabel label1 = new JLabel("I have a tooltip");
label1.setToolTipText("This is the the tooltip for label 1.");
JLabel label2 = new JLabel("I have a tooltip too.");
label2.setToolTipText("This is the the tooltip for label 2.");
contentPane.add(label1);
contentPane.add(Box.createHorizontalStrut(50));
contentPane.add(label2);
contentPane.setBorder(BorderFactory.createEmptyBorder(100, 10, 100, 0));
frame.setContentPane(contentPane);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
}
}
Run the code, then move the mouse pointer from outside the JFrame to be over the top of one of the two labels. You should see the tooltip flicker for a fraction of a second then disappear.
I can't reproduce this on Windows.
I'm using Java 1.8.0_101 on macOS Sierra. I can reproduce it on early versions of OS X, and earlier versions of Java.
The problem goes away if the JFrame is not set to be alwaysOnTop.
Any work-around you can conceive?
Upvotes: 2
Views: 246