我正在使用枚举值初始化一个通用 JavaFX 8 ComboBox,如下所示:
ObservableList<MyEnumClass> myValues = FXCollections
.observableArrayList(MyEnumClass.FIRST_ENUM,
MyEnumClass.SECOND_ENUM, MyEnumClass.THIRD_ENUM);
myEnumComboBox = new ComboBox<MyEnumClass>(myValues);
测试应用程序按预期显示具有 Enum 值的 ComboBox,并且选择其他值也可以正常工作。但有一件事让我感到困惑:尽管我没有观察到任何明显的故障,但每当我从 ComboBox 的菜单中选择一个新值时,我的 Eclipse 控制台仍然会通知我线程“JavaFX 应用程序线程”中的异常。该异常似乎与隐藏 ComboBox 弹出控件的本机 JavaFX 代码有关:
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: null source
at java.util.EventObject.<init>(Unknown Source)
at java.awt.AWTEvent.<init>(Unknown Source)
at sun.awt.UngrabEvent.<init>(Unknown Source)
at javafx.embed.swing.SwingNode$10.handle(Unknown Source)
[9 lines omitted]
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at com.sun.javafx.stage.WindowPeerListener.focusUngrab(Unknown Source)
[4 lines omitted]
at com.sun.glass.ui.Window.handleWindowEvent(Unknown Source)
at com.sun.glass.ui.Window.notifyFocusUngrab(Unknown Source)
at com.sun.glass.ui.win.WinWindow._ungrabFocus(Native Method)
at com.sun.glass.ui.Window.ungrabFocus(Unknown Source)
at com.sun.javafx.tk.quantum.WindowStage.ungrabFocus(Unknown Source)
at javafx.stage.Window.decreaseFocusGrabCounter(Unknown Source)
at javafx.stage.PopupWindow.handleAutohideActivation(Unknown Source)
at javafx.stage.PopupWindow.impl_visibleChanged(Unknown Source)
at javafx.stage.Window$9.invalidated(Unknown Source)
at javafx.beans.property.BooleanPropertyBase.markInvalid(Unknown Source)
at javafx.beans.property.BooleanPropertyBase.set(Unknown Source)
at javafx.stage.Window.setShowing(Unknown Source)
at javafx.stage.Window.hide(Unknown Source)
at javafx.stage.PopupWindow.hide(Unknown Source)
at com.sun.javafx.scene.control.skin.ComboBoxPopupControl.hide(Unknown Source)
[44 lines omitted]
at java.lang.Thread.run(Unknown Source)
有人可以解释这里到底发生了什么以及我可以或应该做些什么吗?
编辑- 异常是由之前在与组合框相同的窗格上进行的一些实验中剩余的SwingNode引起的。删除 SwingNode 使异常消失。