Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX open new window

Tags:

javafx-2

Looking at this code they show a way to display a new window after a login. When username and password are correct it opens new dialog. I want a button click to open new dialog, without checking for username and password.

like image 418
MehmanBashirov Avatar asked Feb 23 '13 14:02

MehmanBashirov


People also ask

How do I create a new JavaFX window?

javafx Windows Creating a new Window // create sample content Rectangle rect = new Rectangle(100, 100, 200, 300); Pane root = new Pane(rect); root. setPrefSize(500, 500); Parent content = root; // create scene containing the content Scene scene = new Scene(content); Stage window = new Stage(); window.


1 Answers

If you just want a button to open up a new window, then something like this works:

btnOpenNewWindow.setOnAction(new EventHandler<ActionEvent>() {     public void handle(ActionEvent event) {         Parent root;         try {             root = FXMLLoader.load(getClass().getClassLoader().getResource("path/to/other/view.fxml"), resources);             Stage stage = new Stage();             stage.setTitle("My New Stage Title");             stage.setScene(new Scene(root, 450, 450));             stage.show();             // Hide this current window (if this is what you want)             ((Node)(event.getSource())).getScene().getWindow().hide();         }         catch (IOException e) {             e.printStackTrace();         }     } } 
like image 53
blo0p3r Avatar answered Nov 08 '22 20:11

blo0p3r