Adjust display of a monitor resolution-independent application

Asked

Viewed 956 times

0

I made an application Java And I realized that when it runs on a computer with higher resolution, it gets smaller. How to adjust display of a monitor resolution-independent application?

1 answer

1


You can catch the screen size with the method Toolkit.getScreenSize().

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double width = screenSize.getWidth();
double height = screenSize.getHeight();

In a configuration for multiple monitors you must use this:

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

If you want to get the resolution in DPI you can use the method getScreenResolution() class Toolkit.

References:
javadoc - Toolkit.getScreenSize()
On Linux there may be a bug has a fix here!
Good Luck!

  • Herbert, I’m weak on this. I don’t know how to implement this in the code.

  • I got... thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.