【发布时间】:2011-04-22 10:34:13
【问题描述】:
我对 JSlider.setValue 的调用有时会阻塞线程,从而导致整个应用程序死锁。
这是阻塞线程的堆栈跟踪。
Thread [RenderThread] (Suspended)
JSlider(Component).getMousePosition() line: not available [local variables unavailable]
SynthSliderUI.calculateThumbLocation() line: not available [local variables unavailable]
BasicSliderUI$Handler.stateChanged(ChangeEvent) line: not available
DefaultBoundedRangeModel.fireStateChanged() line: not available [local variables unavailable]
DefaultBoundedRangeModel.setRangeProperties(int, int, int, int, boolean) line: not available
DefaultBoundedRangeModel.setValue(int) line: not available
JSlider.setValue(int) line: not available
TimeLine.setTime(double) line: 422
GLFrame.display() line: 302
GLFrame$2.renderCallback() line: 188
LWJGLBinding$1.paintGL() line: 49
LWJGLBinding$1(AWTGLCanvas).paint(Graphics) line: 314
LWJGLBinding$1(AWTGLCanvas).update(Graphics) line: 343
GLFrame$2(LWJGLBinding).startRendering() line: 78
GLFrame$3.run() line: 267
这似乎与 nimbus 外观和感觉有关,因为我不会在默认外观中发生。
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
}
catch (Exception e)
{
e.printStackTrace();
}
编辑: 使用 invokeLater 我确实得到了这个异常:
at javax.swing.plaf.synth.SynthTreeUI.paint(Unknown Source)
at javax.swing.plaf.synth.SynthTreeUI.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.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.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.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(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)
【问题讨论】:
-
确保在 EDT 上调用 setValue
-
好的,谢谢。推荐的方法是什么?
-
SwingUtilites.invokeLater(new Runnable(){ public void run(){ / *Your code */ }}) -
好的,谢谢!这样就解决了问题!
-
@Frozen,您应该将其移至答案,以便@clamp 可以接受。