Reputation: 524
Is there a way to keep my scenes in separate Java files in a JavaFx application? I tried something like this:
public class MyApp extends Application
{
private void init(Stage primaryStage)
{
Group root = new Group();
primaryStage.setResizable(false);
Login login = new Login(root, primaryStage); // from another file
primaryStage.setScene(login);
}
I have to close my login scene after authentication and load another scene from another file, so I'm passing the primaryStage
as a parameter for my login Scene
to use stage.close()
Is there a better way for doing that?
My Login scene file
public class Login extends Scene
{
public Login(Group root, final Stage stage)
{
super(root, 265, 390, Color.web("EBE8E3"));
Is there another way to reference the current scene stage?
Upvotes: 0
Views: 334
Reputation: 36722
You don't have to pass the stage
as a parameter. The stage is always available from the nodes of the current scene !
scene.getWindow()
This returns the current stage/window of the scene !
Javadocs : http://docs.oracle.com/javafx/2/api/javafx/scene/Scene.html#getWindow%28%29
Example : How to get parent Window in FXML Controller?
http://blog.crisp.se/2012/08/29/perlundholm/window-scene-and-node-coordinates-in-javafx
Upvotes: 1