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

Custom Slider UI throws NPE with Nimbus

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0_10-beta"
      Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b22)
      Java HotSpot(TM) Client VM (build 11.0-b11, mixed mode, sharing)

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

      A DESCRIPTION OF THE PROBLEM :
      Custom SliderUI throws a NullPointerException when displayed with Nimbus look and feel.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A slider as with java TestCustomSlider
      ACTUAL -
      Exception in thread "main" java.lang.NullPointerException
              at javax.swing.plaf.basic.BasicSliderUI.calculateContentRect(Unknown Source)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      C:\Java\projects\playground>java -Dswing.defaultlaf=com.sun.java.swing.plaf.nimb
      us.NimbusLookAndFeel TestCustomSlider
      Exception in thread "main" java.lang.NullPointerException
              at javax.swing.plaf.basic.BasicSliderUI.calculateContentRect(Unknown Source)
              at javax.swing.plaf.basic.BasicSliderUI.calculateGeometry(Unknown Source)
              at javax.swing.plaf.basic.BasicSliderUI.installUI(Unknown Source)
              at javax.swing.JComponent.setUI(Unknown Source)
              at javax.swing.JSlider.setUI(Unknown Source)
              at TestCustomSlider$1.updateUI(TestCustomSlider.java:14)
              at javax.swing.JSlider.<init>(Unknown Source)
              at javax.swing.JSlider.<init>(Unknown Source)
              at TestCustomSlider$1.<init>(TestCustomSlider.java:12)
              at TestCustomSlider.<init>(TestCustomSlider.java:12)
              at TestCustomSlider.main(TestCustomSlider.java:24)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;
      import javax.swing.plaf.ComponentUI;
      import javax.swing.plaf.basic.BasicSliderUI;

      // javac TestCustomSlider.java
      // java -Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel TestCustomSlider
      public class TestCustomSlider {

          public TestCustomSlider() {
              JFrame mainFrame = new JFrame();
      JSlider jsTortle = new JSlider() {
                  public void updateUI() {
                      setUI((LVSliderUI)LVSliderUI.createUI(this));
                  }
              };
      mainFrame.getContentPane().add(jsTortle);
      mainFrame.pack();
      mainFrame.setVisible(true);
      mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          }
          
          public static void main(String[] args) {
      new TestCustomSlider();
          }
          
          public static class LVSliderUI extends BasicSliderUI {
          
      public static ComponentUI createUI(JComponent c) {
      return new LVSliderUI();
      }

      public LVSliderUI() {
      super(null);
      }

      public void paintThumb(Graphics g) {
      int x = slider.getValue()*slider.getSize().width/100;
      g.setColor(Color.RED);
      g.drawRect(x, 0, 10, 10);
      }
      public void paintTrack(Graphics g) {
      g.setColor(Color.BLUE);
      g.drawLine(0,5,slider.getSize().width, 5);
      }
          }
      }
      ---------- END SOURCE ----------

            jasper Jasper Potts (Inactive)
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: