Similar Q to ToolTip flicker in Java if outside JFrame?
A constantly updating lightweight tooltip works fine, but once it moves out the window bounds or is made heavyweight (by disabling lightweight popups), it's flicker city.
Tried the "-Dsun.awt.noerasebackground=true" hint which works inside a window, but at the expense of some painting artefacts over other components (this example is just a blank panel). Outside a window bounds it doesn't help, there's still horrible amounts of flicker.
Anyone know how to solve this? Or is it not currently possible?
Example is in this code -->
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
public class JTooltipFlickerTest extends JFrame {
JPanel panel;
static public void main (final String[] args) {
new JTooltipFlickerTest ();
}
public JTooltipFlickerTest () {
super ();
//ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
//ToolTipManager.sharedInstance().setReshowDelay(0);
setTitle (this.getClass().toString());
setSize (1024, 768);
this.getContentPane().setLayout (new BorderLayout());
SwingUtilities.invokeLater (
new Runnable () {
@Override
public void run() {
panel = new JPanel ();
final MouseAdapter ma = new MouseAdapter () {
public void mouseMoved (final MouseEvent e) {
panel.setToolTipText ("x: "+e.getX()+", y: "+e.getY());
}
};
panel.addMouseMotionListener(ma);
//panel.setDoubleBuffered(true);
//panel.createToolTip().setDoubleBuffered(true);
JTooltipFlickerTest.this.getContentPane().add (panel, "Center");
JTooltipFlickerTest.this.setVisible (true);
}
}
);
}
}
Somehow, the
javax.swing.RepaintManager
class can help with the tool-tip repaint issue. The class that extends theRepaintManager
below is taken from the example in Chapter 11, Repaint Manager: http://www.java.net/external?url=http://www.curious-creature.org/2007/07/22/repaint-manager-demos-chapter-11/It is modified to repaint
JTooltipFlickerTest
's contentpane...Try to comment out
installRepaintManager()
call in the constructor and you will see the difference...edited
When
installRepaintManager()
is disabled, the whole tooltip flickers on both sides of the the edge boundary (it is the same effect as in OP's original code).When
installRepaintManager()
is enabled, one part of the tooltip area doesn't flicker inside of the edge boundary. In contrast, the other part of it flickers outside of the edge boundary. But, the flicker is not so bad compared to wheninstallRepaintManager()
is disabled.I know, it is a subtle difference which I guess it leaves nothing to be desired of. At least, the words in the tooltip area are a little bit legible when
installRepaintManager()
is enabled.Even when the double-buffered codes are disabled,
installRepaintManager()
works as expected; that is, the heavyweight component is rapidly repainted to reduce the flicker.