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

JSlider pointer not moving in sync with lables for Motif L&F

XMLWordPrintable

    • swing1.1
    • sparc
    • solaris_2.6

      JSlider pointer not moving in sync with lables for Motif L&F

      Steps to reproduce the same,
      1. Run the sample application provided at the end.
      2. Change the L&F to Motif.
      3. Move the slider.

      Notice that the slider pointer does not match with the labels painted.



      -- Sample Code --
      /* JDK1.2
      import java.io.*;
      import java.util.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.swing.*;
      import java.lang.reflect.*;
      */


      /* JDK1.1.X */
      import java.io.*;
      import java.util.*;
      import java.awt.*;
      import java.awt.event.*;
      import com.sun.java.swing.*;
      import java.lang.reflect.*;



      public class TestJS extends JFrame implements ActionListener{
      Container content;
      JPanel mainpanel;
      JPanel panel;
      JSlider slider;
      JMenuBar menubar;

      static String strMotif = "Motif";
      static String motifClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
      static char cMotif = 'o';

      static String strWindows = "Windows";
      static String windowsClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
      static char cWindows = 'W';

      static String strMetal = "Metal";
      static String metalClassName = "com.sun.java.swing.plaf.metal.MetalLookAndFeel";
      static char cMetal = 'M';


      TestJS(String[] args) {
      content = getContentPane();
      content.setLayout(new BorderLayout());
      addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent event){
      System.exit(0);
      }
      }
      );

      mainpanel = new JPanel();
      mainpanel.setLayout(new GridLayout(0, 2, 8, 8));

      //// Slider 1
      panel = new JPanel();
      panel.setBorder(BorderFactory.createTitledBorder("Slider 1"));
      slider = new JSlider(JSlider.HORIZONTAL, 0, 20, 0);
      slider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
      slider.setPaintTicks(true);
      slider.setMajorTickSpacing(10);
      slider.setMinorTickSpacing(2);

      slider.setPaintLabels(true);

      slider.setSnapToTicks(true);
      panel.add(slider);

      mainpanel.add(panel);



      //// Slider 2
      panel = new JPanel();
      panel.setBorder(BorderFactory.createTitledBorder("Slider 2"));
      slider = new JSlider(JSlider.HORIZONTAL, 0, 20, 0);
      slider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
      slider.setPaintTicks(true);

      slider.setMajorTickSpacing(10);
      slider.setMinorTickSpacing(1);

      slider.setPaintLabels(true);

      slider.setSnapToTicks(true);
      panel.add(slider);

      mainpanel.add(panel);

      //// Slider 3
      panel = new JPanel();
      panel.setBorder(BorderFactory.createTitledBorder("Slider 3"));
      slider = new JSlider(JSlider.VERTICAL, 0, 20, 0);
      slider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
      slider.setPaintTicks(true);

      slider.setMajorTickSpacing(10);
      slider.setMinorTickSpacing(2);

      slider.setPaintLabels(true);

      slider.setSnapToTicks(true);
      panel.add(slider);

      mainpanel.add(panel);



      //// Slider 4
      panel = new JPanel();
      panel.setBorder(BorderFactory.createTitledBorder("Slider 4"));
      slider = new JSlider(JSlider.VERTICAL, 0, 20, 0);
      slider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
      slider.setPaintTicks(true);

      slider.setMajorTickSpacing(10);
      slider.setMinorTickSpacing(1);

      slider.setPaintLabels(true);

      slider.setSnapToTicks(true);
      panel.add(slider);

      mainpanel.add(panel);



      menubar = GetLNFMenuBar();
      content.add("North", menubar);
      content.add("Center", mainpanel);
      pack();
      show();
      }


      public void actionPerformed(ActionEvent e) {
      String str = e.getActionCommand();
      if(str.equals(metalClassName) || str.equals(windowsClassName) || str.equals(motifClassName)) {
      changeLNF(str);
      }
      }

      public void changeLNF(String str) {
      System.out.println("Changing LNF to " + str);
      try {
      UIManager.setLookAndFeel(str);
      SwingUtilities.updateComponentTreeUI(TestJS.this);
      TestJS.this.pack();
      }
      catch (Exception exc) {
      showErrorDialog(str);
      }
      }

      public void showErrorDialog(String str) {
      JLabel label = new JLabel("Could not load L&F : " + str);
      JOptionPane.showMessageDialog(null, label, "Error", JOptionPane.ERROR_MESSAGE);
      }


      public JMenuBar GetLNFMenuBar() {
      JMenuBar mbar = new JMenuBar();
      JMenu m = new JMenu("Look and Feel");
      m.setMnemonic('L');
      ButtonGroup bg = new ButtonGroup();

      JRadioButtonMenuItem mi;

      mi = new JRadioButtonMenuItem(strMetal);
      mi.addActionListener(this);
      mi.setActionCommand(metalClassName);
      mi.setMnemonic(cMetal);
      mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
      mi.setSelected(true);
      bg.add(mi);
      m.add(mi);


      mi = new JRadioButtonMenuItem(strWindows);
      mi.addActionListener(this);
      mi.setActionCommand(windowsClassName);
      mi.setMnemonic(cWindows);
      mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
      bg.add(mi);
      m.add(mi);


      mi = new JRadioButtonMenuItem(strMotif);
      mi.addActionListener(this);
      mi.setActionCommand(motifClassName);
      mi.setMnemonic(cMotif);
      mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, ActionEvent.ALT_MASK));
      bg.add(mi);
      m.add(mi);

      mbar.add(m);
      return mbar;
      }

      // Main funtion
      public static void main(String[] args) {
      TestJS TestJS = new TestJS(args);
      }
      }

      -- Sample Code --

            tsantossunw Tom Santos (Inactive)
            mmadhugisunw Mukund Madhugiri (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: