List of usage examples for java.awt Dimension getHeight
public double getHeight()
From source file:UIUtilities.java
public static void setFrameLocationRelativeTo(JFrame f, Component c) { if (c == null) { // Setting the position of the dialog on the center of the screen // in 1.4 should be replaced by // f.setLocationRelativeTo(null); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); f.setLocation((int) d.getWidth() / 2 - (int) f.getPreferredSize().getWidth() / 2, (int) d.getHeight() / 2 - (int) f.getPreferredSize().getHeight() / 2); }/*from w w w .j a v a2 s.com*/ }
From source file:Main.java
/** * Use this static method if you want to center and set its position * compared to the size of the current users screen size. Valid percent is * between +-(0-100) minus is treated as plus, bigger than 100 is always set * to 100./* www . j a v a 2 s. c o m*/ * * @param component * the component you want to center and set size on * @param percentOfScreen * the percent of the current screensize you want the component * to be */ public static void centerComponentInWindow(Component component, int percentOfScreen) { if (percentOfScreen < 0) { centerComponentInWindow(component, -percentOfScreen); return; } if (percentOfScreen > 100) { centerComponentInWindow(component, 100); return; } double percent = percentOfScreen / 100.d; Dimension dimension = component.getToolkit().getScreenSize(); component.setSize((int) (dimension.getWidth() * percent), (int) (dimension.getHeight() * percent)); centerComponentInWindow(component); }
From source file:Main.java
/** * Ensures that all buttons are the same size, and that the chosen size is sufficient to contain the content of any. */// ww w . j a v a 2s.com public static void tieButtonSizes(List<JButton> buttons) { int maxWidth = 0; int maxHeight = 0; for (JButton button : buttons) { Dimension buttonSize = button.getPreferredSize(); maxWidth = (int) Math.max(buttonSize.getWidth(), maxWidth); maxHeight = (int) Math.max(buttonSize.getHeight(), maxHeight); } Dimension maxButtonSize = new Dimension(maxWidth, maxHeight); for (JButton button : buttons) { // Seemingly, to get the GTK+ LAF to behave when there are buttons with and without icons, we need to set every size. button.setPreferredSize(maxButtonSize); button.setMinimumSize(maxButtonSize); button.setMaximumSize(maxButtonSize); button.setSize(maxButtonSize); } }
From source file:Main.java
public static void centerWindowOnScreen(Window window) { Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); window.setLocation((int) (screenSize.getWidth() / 2 - window.getWidth() / 2), (int) (screenSize.getHeight() / 2 - window.getHeight() / 2)); }
From source file:org.syphr.mythtv.apps.previewer.Main.java
private static void centerAndSize(JFrame frame, float size) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setSize((int) (screenSize.getWidth() * size), (int) (screenSize.getHeight() * size)); frame.setLocationRelativeTo(null);/*from w w w . j av a2 s.co m*/ }
From source file:Main.java
public static Dimension currentWindowSize(double widthRatio, double heightRatio) { Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); Dimension rtnDim = new Dimension(); rtnDim.width = new Double(dim.getWidth() * widthRatio).intValue(); rtnDim.height = new Double(dim.getHeight() * heightRatio).intValue(); return rtnDim; }
From source file:Main.java
/** * Use this static method if you want to center a component in Window. * * @param component//from www. ja v a 2 s. co m * the component you want to center in window */ public static void centerComponentInWindow(Component component) { Dimension dimension = component.getToolkit().getScreenSize(); component.setLocation((int) ((dimension.getWidth() - component.getWidth()) / 2), (int) ((dimension.getHeight() - component.getHeight()) / 2)); component.validate(); component.repaint(); }
From source file:Main.java
/** * Centers the window on the screen./* w w w . j a va2s . com*/ * * @param window The window to center. * @return The location or top-left corner. */ public static Point centerOnScreen(Window window) { Dimension screenSize = getScreenSize(window); Dimension windowSize = window.getSize(); int x = (int) ((screenSize.getWidth() - windowSize.getWidth()) / 2); int y = (int) ((screenSize.getHeight() - windowSize.getHeight()) / 2); window.setLocation(x, y); return window.getLocation(); }
From source file:Main.java
public static void setScreenCenter(Container container) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension screenDimension = toolkit.getScreenSize(); int width = container.getWidth(); int height = container.getHeight(); Point point = new Point(); point.setLocation((screenDimension.getWidth() - width) / 2, (screenDimension.getHeight() - height) / 2); container.setLocation(point);/*from w ww . ja v a2s . c o m*/ }
From source file:Main.java
public static void centerWindow(Window window, int width, int height) { // Get screen size final Toolkit tk = Toolkit.getDefaultToolkit(); final Dimension screensize = tk.getScreenSize(); // Set window minimum size window.setMinimumSize(new Dimension((int) Math.floor(screensize.getWidth() * 0.3), (int) Math.floor(screensize.getHeight() * 0.3))); // Set window size if (width == 0f) width = (int) Math.floor(screensize.getWidth() * 0.8); if (height == 0f) height = (int) Math.floor(screensize.getHeight() * 0.8); window.setPreferredSize(new Dimension(width, height)); int left = (int) (screensize.getWidth() - width) / 2; int right = (int) (screensize.getHeight() - height) / 2; ;//from ww w. ja v a 2 s . c o m // Center window window.setLocation(left, right); }