I made a Java
application and realized that when it runs on a computer with a higher resolution, it gets smaller. How to adjust display of an application independent of monitor resolution?
I made a Java
application and realized that when it runs on a computer with a higher resolution, it gets smaller. How to adjust display of an application independent of monitor resolution?
You can get the screen size with the Toolkit.getScreenSize()
method.
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double width = screenSize.getWidth();
double height = screenSize.getHeight();
In a multi-monitor configuration you should use this:
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();
If you want to get the DPI resolution you can use the getScreenResolution()
method of the Toolkit
class.
References:
javadoc - Toolkit.getScreenSize ()
On Linux a bug may occur has a fix here !
Home
Good Luck!