Sunday, February 12, 2012

JavaFX 2.0: Full Screen scene

To make the scene occupy full screen, use the code:
Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
Scene scene = new Scene(root, screenBounds.getWidth(), screenBounds.getHeight());


JavaFX 2.0: Full Screen scene
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javafx_fullscreen;

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

/**
*
* @author erix7
*/
public class JavaFX_FullScreen extends Application {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});

StackPane root = new StackPane();

//Make scene occupy full screen
Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
Scene scene = new Scene(root, screenBounds.getWidth(), screenBounds.getHeight());

root.getChildren().add(btn);
primaryStage.setScene(scene);
primaryStage.show();
}
}

No comments:

Post a Comment