Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JavaFX pop up using seperate fxml file

2890489Feb 23 2015 — edited Feb 23 2015

I have been scanning the forums and cannot find the solution I need, so apologies if this is a repost.

I have created an application in SceneBuilder, and want to call a pop up (also created separately in scene builder) when a certain button is pressed.

How?

Comments

RCC

I use something similar to the following because I want to access methods of the sub window's controller :

FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/my/javafx/Stuff.fxml"));

Parent root = (Parent) loader.load();

MyStuffController controller = (MyStuffController) loader.getController();

Scene scene = new Scene(root);

Stage stage = new Stage();

stage.setScene(scene);

stage.setTitle("My Window");

stage.show();

You can also do it like this

FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/my/javafx/Stuff.fxml"));

Parent root = (Parent) fxmlLoader.load();

Scene scene = new Scene(root);

Stage stage = new Stage();

stage.setScene(scene);

stage.setTitle("My Window");

stage.show();

if you want more of a popup feel, you can use other options to style the window and make it unmovable

stage.initModality(Modality.APPLICATION_MODAL);

stage.initStyle(StageStyle.UNDECORATED);

1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 23 2015
Added on Feb 23 2015
1 comment
3,455 views