我正在编写一个NetBeans插件,需要一些图表。当我将JavaFX图表嵌入到TopComponent中时,我看到了一个NullPointer异常。当我最大化我为我的插件创建的任何其他TopComponent时,我看到以下异常:
java.lang.NullPointerException
at javafx.embed.swing.JFXPanel$HostContainer$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
[catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
该插件仍在运行,除了弹出此异常外,似乎没有其他错误。 TopComponent已注册
@TopComponent.Registration(mode = "commonpalette", openAtStartup = true)
和持久性类型 persistenceType = TopComponent.PERSISTENCE_NEVER
我正在使用
创建图表Platform.setImplicitExit(false);
Platform.runLater(new Runnable() {
@Override
public void run() {
//creating scene here <other code>
myPanel.setScene(scene);
}
});
然后将其直接添加到GroupLayout到TopComponent
this.setLayout(layout);
//then adding myPanel to the layout
如果还值得注意的话,我也会看到这个错误
Dangerous reflection access to sun.misc.SharedSecrets by class com.sun.javafx.tk.quantum.QuantumToolkit$17 detected!
code location: jar:file:/C:/<my_plugin>/build/cluster/modules/ext/jfxrt.jar!/
但是我一直认为我可以忽略这个?
之前是否还有其他人遇到此问题或者可以看到出现了什么问题?我已经尝试了其他布局,检测JavaFX面板何时被移除并且还没有找到解决方案。任何建议将不胜感激:)
作为参考,我的JavaFX版本是2.2.45,NetBeans IDE是最新的。
由于
答案 0 :(得分:1)
最后解决了这个问题,它涉及监听topcomponent的jpanel变为null,然后删除javafx面板,稍后在显示时读取。