Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5042769

Reusing a JToolTip does not work

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 1.4.0
    • client-libs
    • None
    • beta
    • sparc
    • solaris_7

      We wanted the ability to reuse a tooltip, but it turns out this is problematic.
      If you try the following code you'll notice on the second time the tool tip
      shows the raw html instead of the formatted html.

      import java.awt.*;
      import javax.swing.*;
      import javax.swing.border.*;

      public class Test {
          public static void main(String[] args) {
              JFrame frame = new JFrame("Test");
              JScrollBar sb = new JScrollBar(JScrollBar.VERTICAL, 0, 30, 0, 100);
              frame.getContentPane().setLayout(new BorderLayout());
              JPanel panel = new JPanel(new BorderLayout()) {
                  private JToolTip tip;

                  public JToolTip createToolTip() {
                      if (tip == null) {
                          tip = new JToolTip();
                          tip.setComponent(this);
                      }
                      return tip;
                  }
              };
              panel.setToolTipText("<html>HAR<b>BOLD</b>");
              
              panel.setBorder(new EmptyBorder(10, 10, 10, 10));
              panel.add(sb);
              frame.add(panel);
              frame.pack();
              frame.show();
          }
      }

            alexp Alexander Potochkin (Inactive)
            svioletsunw Scott Violet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: