List of usage examples for java.awt Dimension getWidth
public double getWidth()
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:Main.java
/** * Centers a component on screen.//from ww w . jav a2 s. co m * * @param c The component that will be centered. */ public static void centerComponentOnScreen(Component c) { // Size of the screen. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); double width = screenSize.getWidth(); double height = screenSize.getHeight(); // Size of the component. Dimension size = c.getSize(); width -= size.getWidth(); height -= size.getHeight(); c.setLocation((int) width / 2, (int) height / 2); }
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
/** * Displays a message dialog with given information. *//*w w w .j a va 2s. c om*/ public static void showInformationDialog(Component component, String message) { final JPanel panel = new JPanel(new BorderLayout(5, 5)); final JLabel messageLabel = new JLabel(message); messageLabel.setFont(new Font("Dialog", Font.BOLD, messageLabel.getFont().getSize())); panel.add(messageLabel, BorderLayout.CENTER); // Adjust stack trace dimensions final Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); screenDimension.setSize(screenDimension.getWidth() * 0.7, screenDimension.getHeight() * 0.7); final Dimension maxStackTraceDimension = new Dimension(500, 500); maxStackTraceDimension.setSize(Math.min(maxStackTraceDimension.getWidth(), screenDimension.getWidth()), Math.min(maxStackTraceDimension.getHeight(), screenDimension.getHeight())); JOptionPane.showMessageDialog(component, panel, "Information", JOptionPane.INFORMATION_MESSAGE); }
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.//from w w w . j a v a 2 s.co 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
/** * Use this static method if you want to center a component in Window. * * @param component/*from ww w . ja va 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: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);//ww w . ja v a 2 s .c o m }
From source file:Main.java
/** * Centers the window on the screen.// w ww .j a v a 2s . co m * * @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 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 w ww .j a v a2 s . co m // Center window window.setLocation(left, right); }
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 w w.j a v a 2 s . co m }