List of usage examples for java.awt Component getSize
public Dimension getSize()
From source file:pcgen.gui2.tools.Utility.java
/** * Centers a {@code Component} to the screen. * * @param dialog JDialog dialog to center *//*w ww. j av a 2 s . c o m*/ public static void centerComponent(Component dialog) { // since the Toolkit.getScreenSize() method is broken in the Linux implementation // of Java 5 (it returns double the screen size under xinerama), this method is // encapsulated to accomodate this with a hack. // TODO: remove the hack, once Java fixed this. // final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final Rectangle screenSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); final Dimension dialogSize = dialog.getSize(); if (dialogSize.height > screenSize.height) { dialogSize.height = screenSize.height; } if (dialogSize.width > screenSize.width) { dialogSize.width = screenSize.width; } dialog.setSize(dialogSize); dialog.setLocation(screenSize.x + ((screenSize.width - dialogSize.width) / 2), screenSize.y + ((screenSize.height - dialogSize.height) / 2)); }
From source file:pcgen.gui2.tools.Utility.java
/** * Update the size of the dialog to ensure it will fit on the screen. * * @param dialog The dialog to be resized. *//*from w w w . j a v a 2 s.co m*/ public static void resizeComponentToScreen(Component dialog) { // Get the maximum window size to account for taskbars etc Rectangle screenBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); final Dimension dialogSize = dialog.getSize(); if (dialogSize.height > screenBounds.height) { dialogSize.height = screenBounds.height; } if (dialogSize.width > screenBounds.width) { dialogSize.width = screenBounds.width; } dialog.setSize(dialogSize); }
From source file:pcgen.gui2.tools.Utility.java
/** * Centers a {@code JFrame} to the screen. * * @param frame JFrame frame to center * @param isPopup boolean is the frame a popup dialog? *//* w w w . j av a 2 s . c om*/ public static void centerComponent(Component frame, boolean isPopup) { // since the Toolkit.getScreenSize() method is broken in the Linux implementation // of Java 5 (it returns double the screen size under xinerama), this method is // encapsulated to accomodate this with a hack. // TODO: remove the hack, once Java fixed this. // final Dimension screenSize = getScreenSize(Toolkit.getDefaultToolkit()); final Rectangle screenSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); if (isPopup) { frame.setSize(screenSize.width / 2, screenSize.height / 2); } final Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation(screenSize.x + ((screenSize.width - frameSize.width) / 2), screenSize.y + ((screenSize.height - frameSize.height) / 2)); }