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

Adding a mouselistener to JScrollPanes viewport causes the pane to lose tooltip

XMLWordPrintable

    • generic, x86
    • generic, windows_2000, windows_xp

      Name: jk109818 Date: 10/28/2002


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



      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      Adding a mouselistener to the JScrollPane's viewport causes
      the JScrollPane not to display its tooltip.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1.compile and run the example program
      2.check that the bottom part of table (jscrollpane) has no
      tooltip
      3.uncomment the 2 commented lines in code
      4.recompile and run
      5.check that the bottom part of table (jscrollpane) now has
      the tooltip

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The JScrollPane should have the tooltip displayed on both
      occasions. It is only displayed when you have not added a
      mouselistener to the viewport.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;
      import java.awt.Component;
      import java.awt.Container;
      import java.awt.HeadlessException;
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseListener;
      import java.util.Vector;

      public class JScrollPaneToolTipTest extends JFrame {
      public JScrollPaneToolTipTest() throws HeadlessException {
      super("test");
      Vector rows = new Vector();
      Vector cols = new Vector();
      JPanel panel = new JPanel();
      cols.add("a");
      cols.add("b");
      JTable table = new JTable(rows, cols);
      JScrollPane pane = new JScrollPane(table);
      pane.setToolTipText("jscrollpane tooptip");
      panel.add(pane);
      getContentPane().add(panel);
      addMouseListenerToChildren(this, new DummyMouseListener());
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      pack();
      setVisible(true);
      }

      public void addMouseListenerToChildren(Component parent, MouseListener
      l) {
      if (parent instanceof Container == true) {
      Container container = (Container) parent;
      Component[] components = container.getComponents();
      for (int i = 0 ; i < components.length ; i++) {
      Component component = components[i];
      addMouseListenerToChildren(component, l);
      }
      }
      // if (parent instanceof JViewport == false) {
      parent.addMouseListener(l);
      // }
      }

      public static void main(String[] args) {
      JScrollPaneToolTipTest test = new JScrollPaneToolTipTest();
      }

      private class DummyMouseListener extends MouseAdapter {
      }
      }

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

      CUSTOMER WORKAROUND :
      Check that you never add a mouselistener to the viewport.
      (Review ID: 165281)
      ======================================================================
      This contribution from java.net member leouser


      A DESCRIPTION OF THE FIX :
      BUGID: 4769783 Adding a mouselistener to JScrollPanes viewport cause the pane to lose tooltip
      FILES AFFECTED: javax.swing.JScrollPane
      JDK VERSION
      jdk-6-rc-bin-b64-linux-i586-15_dec_2005.bin

      This should be closed:

      Discusion(embeded in test case as well):
      /**
       * BUGID: 4769783 Adding a mouselistener to JScrollPanes viewport cause the pane to lose tooltip
       * This bug apparently does not exist anymore. The synopsis that adding a MouseListener
       * to the viewport will block MouseEvents from trickling down to the proper
       * component appears to be no longer correct. Everything appears to work! :D
       *
       * To see the JScrollPane tooltip in effect you have to go the edges to get it.
       * If your off a little it won't show. The JTable shows to... so their
       * isn't any blocking by the JViewport.
       *
       * So: Close this baby!!!!
       *
       * FILES AFFECTED: javax.swing.JScrollPane
       *
       * JDK VERSION
       * jdk-6-rc-bin-b64-linux-i586-15_dec_2005.bin
       *
       * test ran succesfully on a SUSE 7.3 Linux distribution
       *
       * Brian Harry
       * ###@###.###
       * Jan 23, 2006
       */

      JUnit TESTCASE :
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import static java.lang.System.*;

      /**
       * BUGID: 4769783 Adding a mouselistener to JScrollPanes viewport cause the pane to lose tooltip
       * This bug apparently does not exist anymore. The synopsis that adding a MouseListener
       * to the viewport will block MouseEvents from trickling down to the proper
       * component appears to be no longer correct. Everything appears to work! :D
       *
       * To see the JScrollPane tooltip in effect you have to go the edges to get it.
       * If your off a little it won't show. The JTable shows to... so their
       * isn't any blocking by the JViewport.
       *
       * So: Close this baby!!!!
       *
       * FILES AFFECTED: javax.swing.JScrollPane
       *
       * JDK VERSION
       * jdk-6-rc-bin-b64-linux-i586-15_dec_2005.bin
       *
       * test ran succesfully on a SUSE 7.3 Linux distribution
       *
       * Brian Harry
       * ###@###.###
       * Jan 23, 2006
       */
      public class MListen4769783 implements Runnable{



          public void run(){

      JFrame jf = new JFrame();
      Object[][] data = new Object[1000][10];
              Object[] names = new Object[10];
              for(int i = 0; i<1000; i++){
      for(int i2 = 0; i2 <10; i2++)
                      data[i][i2] = i2;
              }
      for(int i = 0; i < 10; i++)
                  names[i] = String.valueOf(i);

      JTable jtable = new JTable(data, names);
              jtable.setToolTipText("I AM JTABLE!!!");
              JScrollPane jsp = new JScrollPane(jtable);
              jsp.setToolTipText("Mooooo");
      //out.println(jsp.getViewport());
              JPanel jp = new JPanel();
              jp.add(jsp);
              jf.add(jp);
              jf.pack();
              jf.setVisible(true);
              for(Component c: jsp.getComponents()){
      out.println(c);
                  c.addMouseListener(new DummyMouseListener(c));
              }
              jsp.addMouseListener(new DummyMouseListener(jsp));

          }

          private static class DummyMouseListener extends MouseAdapter{
              
              Component c;
              public DummyMouseListener(Component c){
                  this.c = c;
              }
              @Override
      public void mouseEntered(MouseEvent me){
      out.println("MOUSE ENTERED!!! for:\n");
      out.println(c);
              }
              @Override
              public void mouseClicked(MouseEvent me){
                  out.println("MOUSE CLICKED!!! for:\n");
                  out.println(c);
              }
              @Override
              public void mouseExited(MouseEvent me){
      out.println( "MOUSE EXITED!!! for:\n");
                  out.println(c);
              }
              @Override
              public void mousePressed(MouseEvent me){
                  out.println( "MOUSE PRESSED!!! for:\n");
      out.println(c);
              }
              @Override
              public void mouseReleased(MouseEvent me){
                  out.println( "MOUSE RELEASED!!! for:\n");
      out.println(c);
              }
          }

          public static void main(String ... args){
      SwingUtilities.invokeLater(new MListen4769783());
          }
      }


      FIX FOR BUG NUMBER:
      4769783

            alexp Alexander Potochkin (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: