From b822e517533cb8da76776f6b1562d2dff5c3836e Mon Sep 17 00:00:00 2001 From: mdb Date: Wed, 13 Jun 2007 17:01:18 +0000 Subject: [PATCH] Use the multi-head aware Graphics{Environment,Device,Configuration} to center windows if possible as Toolkit isn't smart about such things. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2112 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/swing/util/SwingUtil.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/java/com/samskivert/swing/util/SwingUtil.java b/src/java/com/samskivert/swing/util/SwingUtil.java index 13c890f9..f529452e 100644 --- a/src/java/com/samskivert/swing/util/SwingUtil.java +++ b/src/java/com/samskivert/swing/util/SwingUtil.java @@ -77,10 +77,18 @@ public class SwingUtil */ public static void centerWindow (Window window) { - Toolkit tk = window.getToolkit(); - Dimension ss = tk.getScreenSize(); + Rectangle bounds; + try { + bounds = GraphicsEnvironment.getLocalGraphicsEnvironment(). + getDefaultScreenDevice().getDefaultConfiguration().getBounds(); + } catch (Throwable t) { + Toolkit tk = window.getToolkit(); + Dimension ss = tk.getScreenSize(); + bounds = new Rectangle(0, 0, ss.width, ss.height); + } + int width = window.getWidth(), height = window.getHeight(); - window.setBounds((ss.width-width)/2, (ss.height-height)/2, + window.setBounds(bounds.x + (bounds.width-width)/2, bounds.y + (bounds.height-height)/2, width, height); }