1. Annalena Alice
  2. JavaFX
  3. Friday, 20 July 2018
  4.  Subscribe via email
how can i open new window on button click event .
Comment
There are no comments made yet.
Accepted Answer Pending Moderation
0
Votes
Undo
This is the suitable code for your question:


import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class OpenNewModelessWindowExample extends Application {

@Override
public void start(final Stage primaryStage) {

Button button = new Button();
button.setText("Open a New Window");

button.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {

Button newButton= new Button ("I'm a Button on new Window");

StackPane secondaryLayout = new StackPane();
secondaryLayout.getChildren().add( newButton);

Scene secondScene = new Scene(secondaryLayout, 230, 100);

// New window (Stage)
Stage newWindow = new Stage();
newWindow.setTitle("Second Stage");
newWindow.setScene(secondScene);

// Set position of second window, related to primary window.
newWindow.setX(primaryStage.getX() + 200);
newWindow.setY(primaryStage.getY() + 100);

newWindow.show();
}
});

StackPane root = new StackPane();
root.getChildren().add(button);

Scene scene = new Scene(root, 450, 250);

primaryStage.setTitle("JavaFX Open a new Window");
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) {
launch(args);
}

}

Comment
There are no comments made yet.
  1. more than a month ago
  2. JavaFX
  3. # 1
Accepted Answer Pending Moderation
0
Votes
Undo
You can open a fxml window in another stage on button click by creating the onClick() or create the object of Button Class and put the code in the .setAction().



public void button1() throws IOException
{
Parent part = FXMLLoader.load(getClass().getResource("/ProjectFXML/abc.fxml"));
Stage stage = new Stage();
Scene scene = new Scene(part);
stage.setScene(scene);
stage.show();
}
Comment
There are no comments made yet.
  1. more than a month ago
  2. JavaFX
  3. # 2
Accepted Answer Pending Moderation
0
Votes
Undo
If you are looking for a healthy diet plan...! Here we offer you a fibromyalgia diet plan for free of cost.
Comment
There are no comments made yet.
  1. more than a month ago
  2. JavaFX
  3. # 3
Accepted Answer Pending Moderation
0
Votes
Undo
How to open new FXML window in another stage on button click? Different window FXML on different stages are be different you should choose best essays review for different times because different clicks are be done at different places and you guys check that different clicks.
Comment
There are no comments made yet.
  1. more than a month ago
  2. JavaFX
  3. # 4
  • Page :
  • 1


There are no replies made for this post yet.
Be one of the first to reply to this post!
Guest
Submit Your Response
Share Location

Sharing your current location while posting a new question allow viewers to identify the location you are located.

Latitude:
Longitude:
Captcha
To protect the site from bots and unauthorized scripts, we require that you enter the captcha codes below before posting your question.