JSlider, labelTable, maximum int value and Java 6 problem

I ran into a problem with the JSlider and labelTable when using the maximum int value (2147483647). The JSlider doesn't get painted and exceptions are thrown (see the end of this message).

I run the code from Eclipse, as a JavaBean. The jre used is:

java version "1.6.0_01"

Java(TM) SE Runtime Environment (build 1.6.0_01-b06)

Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

The code below does work when using a smaller value than the max int. It also works with the max int when using an earlier version of java, like 1.5.

Could this be considered a bug?

import java.awt.GridBagLayout;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JSlider;

import java.awt.GridBagConstraints;

import java.util.Hashtable;

publicclass SliderMaxextends JPanel{

// doesn't work with this, maximum int value

privatestaticfinalint MAX_INT_VALUE = 2147483647;

// works with this value

// private static final int MAX_INT_VALUE = 2147483646;

privatestaticfinallong serialVersionUID = 1;

private JSlider jSlider =null;

/**

* This is the default constructor

*/

public SliderMax(){

super();

initialize();

}

/**

* This method initializes this

*

* @return void

*/

privatevoid initialize(){

GridBagConstraints gridBagConstraints =new GridBagConstraints();

gridBagConstraints.fill = GridBagConstraints.VERTICAL;

gridBagConstraints.gridy = 0;

gridBagConstraints.weightx = 1.0;

gridBagConstraints.gridx = 0;

this.setSize(200, 50);

this.setLayout(new GridBagLayout());

this.add(getJSlider(), gridBagConstraints);

}

/**

* This method initializes jSlider

*

* @return javax.swing.JSlider

*/

private JSlider getJSlider(){

if (jSlider ==null){

jSlider =new JSlider();

Hashtable<Integer, JLabel> labelTable =new Hashtable<Integer, JLabel>();

labelTable.put(new Integer(0),new JLabel("Start"));

// this label doesn't get painted even if you

// comment out the line jSlider.setMaximum(MAX_INT_VALUE);

// which causes the exceptions

labelTable.put(new Integer(MAX_INT_VALUE),new JLabel("End"));

jSlider.setLabelTable(labelTable);

jSlider.setPaintLabels(true);

// this causes the exceptions

jSlider.setMaximum(MAX_INT_VALUE);

}

return jSlider;

}

}

I get these exceptions:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

at javax.swing.plaf.basic.BasicSliderUI.calculateTrackBuffer(Unknown Source)

at javax.swing.plaf.basic.BasicSliderUI.calculateGeometry(Unknown Source)

at javax.swing.plaf.basic.BasicSliderUI.paint(Unknown Source)

at javax.swing.plaf.ComponentUI.update(Unknown Source)

at javax.swing.JComponent.paintComponent(Unknown Source)

at javax.swing.JComponent.paint(Unknown Source)

at javax.swing.JComponent.paintChildren(Unknown Source)

at javax.swing.JComponent.paint(Unknown Source)

at javax.swing.JComponent.paintChildren(Unknown Source)

at javax.swing.JComponent.paint(Unknown Source)

at javax.swing.JComponent.paintChildren(Unknown Source)

at javax.swing.JComponent.paint(Unknown Source)

at javax.swing.JLayeredPane.paint(Unknown Source)

at javax.swing.JComponent.paintChildren(Unknown Source)

at javax.swing.JComponent.paintToOffscreen(Unknown Source)

at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)

at javax.swing.RepaintManager.paint(Unknown Source)

at javax.swing.JComponent.paint(Unknown Source)

at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)

at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)

at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)

at java.awt.Container.paint(Unknown Source)

at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)

at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)

at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)

at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

at javax.swing.plaf.basic.BasicSliderUI.calculateTrackBuffer(Unknown Source)

at javax.swing.plaf.basic.BasicSliderUI.calculateGeometry(Unknown Source)

at javax.swing.plaf.basic.BasicSliderUI$Handler.componentResized(Unknown Source)

at java.awt.Component.processComponentEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

at javax.swing.plaf.basic.BasicSliderUI.calculateTrackBuffer(Unknown Source)

at javax.swing.plaf.basic.BasicSliderUI.calculateGeometry(Unknown Source)

at javax.swing.plaf.basic.BasicSliderUI$Handler.componentResized(Unknown Source)

at java.awt.Component.processComponentEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

at javax.swing.plaf.basic.BasicSliderUI.calculateTrackBuffer(Unknown Source)

at javax.swing.plaf.basic.BasicSliderUI.calculateGeometry(Unknown Source)

at javax.swing.plaf.basic.BasicSliderUI.paint(Unknown Source)

at javax.swing.plaf.ComponentUI.update(Unknown Source)

at javax.swing.JComponent.paintComponent(Unknown Source)

at javax.swing.JComponent.paint(Unknown Source)

at javax.swing.JComponent.paintToOffscreen(Unknown Source)

at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)

at javax.swing.RepaintManager.paint(Unknown Source)

at javax.swing.JComponent._paintImmediately(Unknown Source)

at javax.swing.JComponent.paintImmediately(Unknown Source)

at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)

at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)

at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)

at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

[10694 byte] By [scandinavian_flicka] at [2007-11-27 5:23:33]
# 1
Just tested it with JDK1.6.0_01, and got the same results. Looks like a bug, although I haven't gone looking for it in the bug database. The bug does not appear with the Nimbus look and feel. Guess swinglabs has a better SliderUI class. You could always change the LAF...
rebola at 2007-7-12 11:49:28 > top of Java-index,Desktop,Core GUI APIs...
# 2
The bug also appears when using the Windows LAF. Haven't tried others. I'm going to search the bug database...
scandinavian_flicka at 2007-7-12 11:49:28 > top of Java-index,Desktop,Core GUI APIs...