Rajat Khandelwal
Rajat Khandelwal

Reputation: 487

Make JavaFx application Fullscreen OnClick

Hello i am making a web browser in javafx and i want to make it fullscreen when user clicks on Fullscreen button. I tried the below given code but unfortunately it is giving error.

Fullscreen.setOnAction(new EventHandler<ActionEvent>() {
  @Override
 public void handle(ActionEvent event) {
   primaryStage.setFullScreen(true);   // here it gives error "cannot find variable primaryStage"
 } 
}); 

**I know that this doesn't follow the basics of java but i didn't find another way of implementing it.
Kindly help :)

Upvotes: 2

Views: 586

Answers (1)

James_D
James_D

Reputation: 209694

Assuming Fullscreen is a button, just get the stage it's in with

((Stage)Fullscreen.getScene().getWindow()).setFullScreen(true);

Upvotes: 1

Related Questions