+
+ /**
+ * Set the given {@link Window} to full screen mode, on the desktop it
+ * currently resides on.
+ * <p>
+ * Can be cancelled by calling again with a NULL value.
+ *
+ * @param win
+ * the window to set to full screen
+ */
+ static public void setFullscreenWindow(Window win) {
+ GraphicsEnvironment env = GraphicsEnvironment
+ .getLocalGraphicsEnvironment();
+ GraphicsDevice[] screens = env.getScreenDevices();
+
+ if (win == null) {
+ for (GraphicsDevice screen : screens) {
+ if (win == null) {
+ screen.setFullScreenWindow(null);
+ }
+ }
+
+ return;
+ }
+
+ Rectangle r = win.getBounds();
+ Point center = new Point(r.x + r.width / 2, r.y + r.height / 2);
+
+ GraphicsDevice current = null;
+ for (GraphicsDevice screen : screens) {
+ GraphicsConfiguration[] confs = screen.getConfigurations();
+ for (GraphicsConfiguration conf : confs) {
+ if (conf.getBounds().contains(center)) {
+ current = screen;
+ break;
+ }
+ }
+
+ if (current != null)
+ break;
+ }
+
+ if (current == null) {
+ current = GraphicsEnvironment.getLocalGraphicsEnvironment()
+ .getDefaultScreenDevice();
+ }
+
+ current.setFullScreenWindow(win);
+ }