Java get MAXIMIZED state window size

此生再无相见时 提交于 2019-12-24 17:24:40

问题


I am developing a multi platform game and I wanted to make a full-screen non bordered window and this is where I got into a problem for LINUX operating system.

For WINDOWS system I was using Toolkit.getDefaultToolkit().getScreenSize() method to get complete SCREEN SIZE and it worked fine, but for LINUX my screen was a bit wider and higher due to LINUX BARS.

*SOLUTION in my answer bellow


回答1:


You could have a look at Full-Screen Exclusive Mode API. This will give your program full access to the whole screen, removing any need for you to be concerned about task/dock bars and the like

Or you could do something like

GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
Rectangle bounds = gd.getDefaultConfiguration().getBounds();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gd.getDefaultConfiguration());

Rectangle safeBounds = new Rectangle(bounds);
safeBounds.x += insets.left;
safeBounds.y += insets.top;
safeBounds.width -= (insets.left + insets.right);
safeBounds.height -= (insets.top + insets.bottom);

Essentially all this does is gets the screen bounds (x/y and width/height), the screens insets for the device and updates the screen bounds to take into consideration things like the task bar and other system resources.

You could also simply try using something like Frame#setExtendedState which will allow you to put the window into Frame.MAXIMIZED_BOTH and let it do the work for you




回答2:


*SOLUTION
After many hours of browsing the internet I already found the solution to get size of the window when its in MAXIMIZED state (Like you press maximize square on frame) and gives you MAXIMUM allowed size of the window paying attention on all OPERATING SYSTEM bars. Here is the method: GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()



来源:https://stackoverflow.com/questions/32555329/java-get-maximized-state-window-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!