1

Here was my original post:

I have an application built in NetBeans 8/ Java8/JavaFX. (Note that I do not have SceneBuilder)

My main application window is running fine. I have a menu item that calls the following function to open a second window:

    @FXML
    private void openChildWindowAlt() throws Exception {

        Group root = new Group();
        Stage stage = new Stage();

        AnchorPane frame = FXMLLoader.load(getClass().getResource("fxml_childWindow1.fxml"));
        root.getChildren().add(frame);
        Scene scene = new Scene(root);

        stage.setScene(scene);
        stage.show();

    }

When I select the menu button, my 2nd stage shows up as expected, but I get the following exception:

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: null source

at java.util.EventObject.<init>(EventObject.java:56)
at java.awt.AWTEvent.<init>(AWTEvent.java:337)
at sun.awt.UngrabEvent.<init>(UngrabEvent.java:48)
at javafx.embed.swing.SwingNode$10.handle(SwingNode.java:414)
at javafx.embed.swing.SwingNode$10.handle(SwingNode.java:410)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)

at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:204)

....there's more, lots more... hopefully this is enough for someone to help.

I have also tried the following, which results in the same exception:

@FXML private void openChildWindow() throws Exception {

Stage stage = new Stage();

AnchorPane root = new AnchorPane();

TabPane myTabPane = new TabPane();

Tab tab1 = new Tab("blue");
Tab tab2 = new Tab("purple");

myTabPane.getTabs().addAll(tab1,tab2);

root.getChildren().add(myTabPane);
stage.setScene(new Scene(root,1200,800));
stage.show();

}

After posting the above, I went back to the application and realized that I get this exception not only when I open these windows, but on ANY click of ANY menu item, no matter what the menu item does.

Any ideas?

Thanks!

-Adeena

adeena
  • 4,027
  • 15
  • 40
  • 52
  • Ok - I found the offending code (I compared it to another application I wrote with a similar top structure, but different content), and in my Controller, in the initialize function... I was using a SwingUtility and something is funky there. When I comment that bit of code out, I don't get the exception. Not sure how this has to do with the menu... but for the moment, I'm exception free... – adeena Feb 24 '14 at 17:18
  • The source of the exception was probably in the "there's more, lots more" part of the stack trace! – assylias Feb 24 '14 at 18:17

1 Answers1

1

My guess is, that you used SwingUtilities.invokeLater. This does not work with JavaFX. There you should use Platform.runLater.

Rainer Schwarze
  • 4,725
  • 1
  • 27
  • 49
  • I did... I did not know that it could not be used with JavaFX. Thanks! – adeena Feb 24 '14 at 19:06
  • A year ago I was exploring JavaFX, Swing, and OSGi and wrote a little about it here: http://blog.admadic.com/2013/03/javafx-and-swing-on-mac.html - there should be code which uses Swing and JavaFX with their background workers :-) – Rainer Schwarze Feb 24 '14 at 19:22
  • Sure I'll take a look! Does this apply to Java 8? I'm finding little things here and there that don't seem to work with Java 8... – adeena Feb 24 '14 at 19:28
  • I used java 8 ea for these things (at least I think so, it's been some time) – Rainer Schwarze Feb 24 '14 at 19:48