java.lang.NullPointerException when scrolling in JComboBox

Hi everybody,

I use a JComboBox in my application. If I scroll it a NullPointerException is thrown:

java.lang.NullPointerException

at javax.swing.BufferStrategyPaintManager.flushAccumulatedRegion(BufferStrategyPaintManager.java:406)

at javax.swing.BufferStrategyPaintManager.copyArea(BufferStrategyPaintManager.java:334)

at javax.swing.RepaintManager.copyArea(RepaintManager.java:1143)

at javax.swing.JViewport.blitDoubleBuffered(JViewport.java:1604)

at javax.swing.JViewport.windowBlitPaint(JViewport.java:1573)

at javax.swing.JViewport.setViewPosition(JViewport.java:1118)

at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.vsbStateChanged(BasicScrollPaneUI.java:1027)

at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(BasicScrollPaneUI.java:1016)

at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel.java:348)

at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeModel.java:285)

at javax.swing.DefaultBoundedRangeModel.setValue(DefaultBoundedRangeModel.java:151)

at javax.swing.JScrollBar.setValue(JScrollBar.java:446)

at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.mouseWheelMoved(BasicScrollPaneUI.java:962)

at java.awt.Component.processMouseWheelEvent(Component.java:6126)

at java.awt.Component.processEvent(Component.java:5810)

at java.awt.Container.processEvent(Container.java:2058)

at java.awt.Component.dispatchEventImpl(Component.java:4410)

at java.awt.Container.dispatchEventImpl(Container.java:2116)

at java.awt.Component.dispatchMouseWheelToAncestor(Component.java:4555)

at java.awt.Component.dispatchEventImpl(Component.java:4296)

at java.awt.Container.dispatchEventImpl(Container.java:2116)

at java.awt.Component.dispatchEvent(Component.java:4240)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4015)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)

at java.awt.Container.dispatchEventImpl(Container.java:2102)

at java.awt.Window.dispatchEventImpl(Window.java:2429)

at java.awt.Component.dispatchEvent(Component.java:4240)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)

at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

This is the code I execute:

publicstaticvoid test()

{

Object[] items =new Object[10];

items[0] = 0;

items[1] = 1;

items[2] = 2;

items[3] = 3;

items[4] = 4;

items[5] = 5;

items[6] = 6;

items[7] = 7;

items[8] = 8;

items[9] = 9;

JFrame frame =new JFrame("Test frame");

JPanel panel =new JPanel();

panel.add(new JLabel("Combobox:"));

panel.add(new JComboBox(items));

frame.add(panel);

frame.pack();

frame.setVisible(true);

}

The weird thing is that if I execute this piece of code outside my program, in a test class, everything goes fine. I am not sure how this is possible.

Best regards,

Jethro Borsje

[4032 byte] By [Jethroa] at [2007-11-27 11:48:49]
# 1

What does the combo box show before you operate it? The first item "0" ?

java_knighta at 2007-7-29 18:21:31 > top of Java-index,Desktop,Core GUI APIs...
# 2

Yes, is start with showing the first item in the list.

Jethroa at 2007-7-29 18:21:31 > top of Java-index,Desktop,Core GUI APIs...
# 3

You not assign any ActionListener to your ComboBox ?

Thunder_Blasta at 2007-7-29 18:21:31 > top of Java-index,Desktop,Core GUI APIs...
# 4

> You not assign any ActionListener to your ComboBox ?

Well, in my real-life implementation I plan to do so, however in the test() method I do not. And the problem is still there in the test method, so to answer your question: no I do not add an ActionListener to the JComoBox in my test case.

A little bit more info: when I scroll in the JComboBox the scrollwheel of my mouse, the scrollbar on the right side does not move, however the contents of the JComboBox does move.

Jethroa at 2007-7-29 18:21:31 > top of Java-index,Desktop,Core GUI APIs...