Skip to main content

Tooltip flashes/flickers in Applet but works correctly in Application

1 reply [Last post]
durby
Offline
Joined: 2003-07-02

The sample code shows a multiline tooltip text (using HTML) displayed on a JLabel.
Multiline used since it is easier to demonstrate the problem.

The init() method is identical in both examples. The difference is one is an Applet the
other an Application (JFrame).

When the examples are executed and the windows moved to the bottom or bottom-right
of the screen and the tooltip appears, the Application shows the tooltip correctly. But, the
Applet's tooltip will flash on/off as quickly as possible.

To reproduce, move the display so the tooltip will appear "under" the mouse when the
tooltip is displayed.
NOTEs:

  • ToolTipManager.setLightWeightPopupEnabled() with true or false had no difference in behavior.
  • The Applet can be run directly from and IDE (e.g., Netbeans) or placed into an "html" page an executed in a browser.
  • The multiline tooltip can be replaced with a single line of text.
  • The same behavior has been reproduced in Java 1.4, 1.5 and 1.6.
  • I have attempted to create custom ToolTipManager, PopupFactory, and Popup implementations, but have not been successful.

Questions:

  1. Why is there a difference in behavior between an Applet and an Application?
  2. How to get ToolTipManager to "move" the tooltip window be relocated on the display to be not under the mouse, similar to a Popup Menu?
  3. Is this a bug in the JRE?

Thanks for any assistance,
paul

Now the example source:

First the application:

<br />
package tooltips;</p>
<p>import java.awt.*;<br />
import javax.swing.*;</p>
<p>/**<br />
 * No flickering occurs when the same tooltip is display in a Frame.<br />
 */<br />
public class AppNoFlickerToolTipDemo extends JFrame {</p>
<p>    public static void main(String[] args) {<br />
        AppNoFlickerToolTipDemo demo = new AppNoFlickerToolTipDemo();<br />
        demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />
        demo.init();<br />
        demo.setSize(200,200);<br />
        demo.setVisible(true);<br />
    }</p>
<p>    public void init() {<br />
        ToolTipManager.sharedInstance().setLightWeightPopupEnabled(true);</p>
<p>        Container appCont = getContentPane();<br />
        appCont.setLayout(new GridLayout(0,1));</p>
<p>        //create the JLabel<br />
        JLabel label = new JLabel("Label with tooltip", JLabel.CENTER);</p>
<p>        ToolTipManager.sharedInstance().registerComponent(label);<br />
        label.setToolTipText(<br />
            "" + label.getText() + "More text to make the tooltip larger than a single line.Why when the tooltip is close to the edge of the display in an Applet does could the tooltip flicker?
<ol>
<li>a
<li>b
<li>c
<li>d</ol>
<p>How to solve this dilemma?"<br />
        );<br />
        appCont.add(label);<br />
    }</p>
<p>}<br />

Now the Applet:

<br />
package tooltips;</p>
<p>import java.awt.*;<br />
import javax.swing.*;</p>
<p>/**<br />
 * When the ToolTip window is to appear and is too close to the edge of the<br />
 * screen, the tooltip will appear and then disappear repeatedly.<br />
 */<br />
public class AppletFlickerToolTipDemo extends JApplet {</p>
<p>    public void init() {<br />
        // setLightWeightPopupEnabled(true) // no difference<br />
        ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);</p>
<p>        Container appCont = getContentPane();<br />
        appCont.setLayout(new GridLayout(0,1));</p>
<p>        //create the JLabel<br />
        JLabel label = new JLabel("Label with tooltip", JLabel.CENTER);<br />
        ToolTipManager.sharedInstance().registerComponent(label);<br />
        label.setToolTipText(<br />
            "" + label.getText() + "More text to make the tooltip larger than a single line.Why when the tooltip is close to the edge of the display in an Applet does could the tooltip flicker?
<ol>
<li>a
<li>b
<li>c
<li>d</ol>
<p>How to solve this dilemma?"<br />
        );<br />
        appCont.add(label);<br />
    }</p>
<p>}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
juggle4evr
Offline
Joined: 2009-02-26

Any new insights/solutions to this problem? I have the same one and it's really annoying...
Regards,
Juergen