5

With

Toolkit.getDefaultToolkit().getScreenSize()

I get the screen size.

But usually this isn't the available size I have for my own program, because on the mac there is a menubar on top and on the bottom an iconbar. Windows also has an iconbar. So how do I get the real available space?

Nosrep
  • 521
  • 7
  • 21
Christian
  • 1,664
  • 1
  • 23
  • 43

2 Answers2

10

From Java forum:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle bounds = ge.getMaximumWindowBounds();

Now you have the bounds sans platform-dependent desktop decorations. I don't have a Mac around so I only verified that it works on WinXP/JDK6.

Note that if you auto-hide taskbar, the bounds do NOT include taskbar, which is correct.

Geoffrey Zheng
  • 6,562
  • 2
  • 38
  • 47
  • @Geoffrey This has the side-effect of changing the Look and Feel of the application, correct? Is this necessary? I don't understand what effect it has on the local `GraphicsEnvironment`. – muffin Aug 08 '14 at 19:22
  • @muffin I think they're just telling you to put the `GraphicsEnvironment` part after look and feel – Nosrep Oct 01 '20 at 13:29
1

I'm not sure if this will work, but try the GraphicsConfiguration/GraphicsDevice instead. You might not be able to get a bounding box that discount the dock on OS X since the area of the dock is still considered screen space. I can move windows on top of it. I can also move the dock to be on the side and not at the bottom of the screen (same goes for the Windows task bar).

http://download.oracle.com/javase/6/docs/api/java/awt/GraphicsDevice.html

Matti Lyra
  • 12,828
  • 8
  • 49
  • 67