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

JSlider with buttons in labeltable: impossible to get Action/Mouse Events

XMLWordPrintable

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


      on FreeBSD:

      java version "1.4.2-p6"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-p6-root_23_feb_2004_13_28)
      Java HotSpot(TM) Client VM (build 1.4.2-p6-root_23_feb_2004_13_28, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux catchy 2.4.26 #1 Sun May 9 09:41:45 EDT 2004 i686 unknown

      also reproduced on:

      FreeBSD twiggy 4.9-STABLE FreeBSD 4.9-STABLE #4: Fri Apr 2 19:46:37 EST 2004 root@twiggy:/usr/obj/usr/src/sys/TWIGGY i386



      A DESCRIPTION OF THE PROBLEM :
      The docs located here:

      http://java.sun.com/docs/books/tutorial/uiswing/components/slider.html

      indicate that you can put JButtons in the labeltable of a JSlider. While they can be added, the functionality described in the tutorial is not available because it is impossible to get ActionEvents or MouseEvents from elements added to the label table. I have brought this issue up in the forums:

      http://forum.java.sun.com/thread.jsp?forum=57&thread=530728

      Either the docs need to be updated to clarify that this can't be done, or, better yet, the functionality needs to be added.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Get the code below (or from http://forum.java.sun.com/thread.jsp?forum=57&thread=530728)
      and compile and run the code. Note that clicking the button cause the slider to move closer to the mouse position, but not to fire an action event.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The docs describe here
      http://java.sun.com/docs/books/tutorial/uiswing/components/slider.html
      that it is possible to add JButtons to the label table of a JSlider to get ActionEvents. The docs specifically say: "This program uses JLabel instances with text only. An interesting variation would be to use JLabel instances with icons, or perhaps buttons that move the knob to the label's position."
      ACTUAL -
      The JButton in the Label table is visible but does not respond to user input.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.util.Hashtable;
      import javax.swing.*;
      import java.awt.event.*;

      public class SliderTest extends JSlider implements ActionListener {
          public SliderTest() {
              super( 0, 100, 50 );
      javax.swing.JComponent label;
      Hashtable labelTable = new Hashtable();
      JButton button;
      labelTable.put(new Integer(75), button = new JButton( "75" ) );
      button.addActionListener( this );
      setLabelTable(labelTable);
      setPaintLabels(true);
          }
          public void actionPerformed( ActionEvent ae ) {
           System.out.println( "75" );
           setValue( 75 );
          }
          public static void main(String[] args) {
           JFrame jf = new JFrame();
           jf.getContentPane().add( new SliderTest() );
           jf.pack();
           jf.show();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I suppose it is possible to put a panel next to the slider an align them, but this seems error prone.

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

              Created:
              Updated:
              Imported:
              Indexed: