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
This commit is contained in:
@@ -77,10 +77,18 @@ public class SwingUtil
|
|||||||
*/
|
*/
|
||||||
public static void centerWindow (Window window)
|
public static void centerWindow (Window window)
|
||||||
{
|
{
|
||||||
Toolkit tk = window.getToolkit();
|
Rectangle bounds;
|
||||||
Dimension ss = tk.getScreenSize();
|
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();
|
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);
|
width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user