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

Computing bounding box of tooltip with HTML elements

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0-ea"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b12)
      Java HotSpot(TM) Client VM (build 1.6.0-ea-b12, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      The bounding box for regular tooltips and HTML tooltips are computed in an inconsistent manner. The attached example illustrates tooltips for JButton and JMenuItem in a popup menu.

      The regular tooltip (the third button) has much less space on the bottom (letters g and p) than on top (letters l and t). The HTML tooltip (the first button) has problems on the left and the right side (a single pixel only), and when the text is in bold, (the second button) the tooltip gets "glued" to the bounding box on the left.

      The same happens with the menu items.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached program, hover over buttons. Right-click on each button and hover over the items in the context menu.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Consistent computation of the bounding box
      ACTUAL -
      As described above

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Dimension;
      import java.awt.FlowLayout;
      import java.awt.event.*;

      import javax.swing.*;
      import javax.swing.border.BevelBorder;

      public class CheckTrans extends JFrame {
          class MousePopupListener extends MouseAdapter {
           public MousePopupListener() {
           }
          
           public void mousePressed(MouseEvent e) { checkPopup(e); }
              public void mouseClicked(MouseEvent e) { checkPopup(e); }
              public void mouseReleased(MouseEvent e) { checkPopup(e); }

              private void checkPopup(MouseEvent e) {
                  if (e.isPopupTrigger( )) {
                   // create popup menu and start populating it
                   JPopupMenu popup = new JPopupMenu();
                      popup.setLabel("Operations");
                      popup.setBorder(new BevelBorder(BevelBorder.RAISED));
                      
                      JMenuItem item1 = new JMenuItem();
                      item1.setText("item 1");
                      item1.setToolTipText("item 1 tooltip text");
                      popup.add(item1);
                      
                      JMenuItem item2 = new JMenuItem();
                      item2.setText("item 2");
                      item2.setToolTipText("<html><b>item 2 tooltip text</b></html>");
                      popup.add(item2);
                      
                      popup.show(e.getComponent(), e.getX( ), e.getY( ));
                  }
              }
          }

          public CheckTrans() {
      JPanel mainPanel = new JPanel();
      mainPanel.setLayout(new FlowLayout());
      JButton button1 = new JButton("button");
      button1.setToolTipText("<html>HTML tooltip text</html>");
      mainPanel.add(button1);
      JButton button2 = new JButton("button");
      button2.setToolTipText("<html><b>bold tooltip text</b></html>");
      mainPanel.add(button2);
      JButton button3 = new JButton("button");
      button3.setToolTipText("regular tooltip text");
      mainPanel.add(button3);

      button1.addMouseListener(new MousePopupListener());
      button2.addMouseListener(new MousePopupListener());
      button3.addMouseListener(new MousePopupListener());

      this.add(mainPanel);

      addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  }
              });
      }

      public static void main(String[] args) {
      CheckTrans ct = new CheckTrans();
      ct.setSize(new Dimension(200, 100));
      ct.setVisible(true);
      }
      }

      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shickeysunw Shannon Hickey (Inactive)
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: