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

JList does not delegate getTooltipLocation() to renderers

    XMLWordPrintable

    Details

    • Subcomponent:
    • Understanding:
      Fix Understood
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      Name: gm110360 Date: 09/24/2004


      FULL PRODUCT VERSION :
      1.4.2_04 and 1.5 RC

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      JList delegates getToolTipText() to the JList renderer component.
      It allows to set a tooltip text for each JList item, from the renderer.

      The delegation is not done for getToolTipLocation(). As a result, overriding the default tooltip location is not possible.

      Overridding JList is a workaround when using JList directly.
      But no workaround is possible when setting tooltip in a JComboBox (that delegates display to JList).



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.MouseEvent;

      import javax.swing.*;

      public class ComboTooltipTest {
          
          private static class MyListRenderer extends DefaultListCellRenderer {
      public Component getListCellRendererComponent(
      JList list,
      Object value,
      int index,
      boolean isSelected,
      boolean cellHasFocus) {

      super.getListCellRendererComponent(
      list,
      value,
      index,
      isSelected,
      cellHasFocus);

      if (value==null) return this;

      super.setToolTipText("My tooltip for "+value);
      return this;
      }

      public Point getToolTipLocation(MouseEvent event) {
      System.out.println("getToolTipLocation");
      return new Point(getWidth()+5,0);
      }
          }

          public static void main(String[] args) {
              
              JComboBox combo=new JComboBox(new String[] { "value1","value2","value3"});
              combo.setRenderer(new MyListRenderer());
              
              JFrame f=new JFrame();
              f.getContentPane().setLayout(new FlowLayout());
              f.getContentPane().add(combo);
              f.setSize(300,200);
              f.setVisible(true);
              
          }
      }

      ---------- END SOURCE ----------
      (Incident Review ID: 311730)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: