How to automatically resize windows in JavaFx for different resolutions?

Dina Bogdan picture Dina Bogdan · Oct 29, 2016 · Viewed 20.9k times · Source

I have the following problem:

I have created a JavaFX window on a desktop with full hd, and I set the scene like this:

Scene scene = new Scene(root,1475,1015);

When I run the application on a laptop with 1360*760 resolution, I can't see the whole application and I can't resize it.

How can I set my application to resize automatically in function of the desktop/laptop and it`s resolution and dimensions?

Answer

Politic Revolutionnaire picture Politic Revolutionnaire · Oct 29, 2016

I believe you are looking for this

GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();

This will allow you to use the screen size of your device and all you need to do to resize is make the length/width of the objects within your program proportional to the width and height of the screen.