我一直在为我的所有 JSlider 使用上述 MetalSliderUI 解决方案。Windows 用户对此感到满意。我很高兴在 stackoverflow.com 上找到此解决方案 该解决方案已在此处讨论: JSlider question: Position after leftclick
现在最近一个 MAC OSX/64 位用户正在尝试使用我的软件,他从 MetalSliderUI 引用中获得了空指针异常。
我添加到 JFrame 的构造函数的代码示例:
// Radio Window Elecraft K3 RFPWR Slider - when click on slider
// go to the value instead of going up/down one tick.
jSliderElecraftK3RFPWR.setUI(
new MetalSliderUI() {
protected void scrollDueToClickInTrack(int direction) {
int value = jSliderElecraftK3RFPWR.getValue();
if (jSliderElecraftK3RFPWR.getOrientation() == JSlider.HORIZONTAL) {
value = this.valueForXPosition(jSliderElecraftK3RFPWR.getMousePosition().x);
} else if (jSliderElecraftK3RFPWR.getOrientation() == JSlider.VERTICAL) {
value = this.valueForYPosition(jSliderElecraftK3RFPWR.getMousePosition().y);
}
jSliderElecraftK3RFPWR.setValue(value);
}
}
);
没有在我的代码中引用确切行的异常:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at
javax.swing.plaf.metal.MetalSliderUI.installUI(MetalSliderUI.java:92) at
javax.swing.JComponent.setUI(JComponent.java:662) at
javax.swing.JSlider.setUI(JSlider.java:300) at
HamRadioIntegrator_N3ZH.JFrameRadio.(JFrameRadio.java) at
HamRadioIntegrator_N3ZH.JFrameRadio$550.run(JFrameRadio.java) at
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at
java.awt.EventQueue.dispatchEventImpl(EventQueue.java:678) at
java.awt.EventQueue.access$000(EventQueue.java:86) at
java.awt.EventQueue$1.run(EventQueue.java:639) at
java.awt.EventQueue$1.run(EventQueue.java:637) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:648) at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296) at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211) at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201) at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196) at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188) at
java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
您对解决仅在 Mac 上发生的此问题有什么建议吗?
霍华德