Skip to content

Instantly share code, notes, and snippets.

@omernaci
Created April 19, 2017 05:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save omernaci/94c767e519139464edc7a8092cabd415 to your computer and use it in GitHub Desktop.
Save omernaci/94c767e519139464edc7a8092cabd415 to your computer and use it in GitHub Desktop.
JavaFX Scene Size with Screen Resolution
import java.awt.Dimension;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class ScreenResolutionDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
double width = screenSize.getWidth() / 3;
double height = screenSize.getHeight() / 2;
try {
primaryStage.setScene(new Scene(new AnchorPane(), width, height));
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment