List of usage examples for java.awt Dimension getHeight
public double getHeight()
From source file:Main.java
public static final void defaultSize(Component component) { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = new Dimension((int) (screen.getWidth() * 2 / 3), (int) (screen.getHeight() * 0.8)); component.setSize(size);/* w w w. ja v a 2 s. c o m*/ }
From source file:Main.java
public static Cursor buildCursorByTrimming(Toolkit toolkit, Image image, int x, int y, String name, Cursor defaultCursor) {/* w w w. j a v a 2s .c o m*/ Dimension d = toolkit.getBestCursorSize(image.getWidth(null), image.getHeight(null)); if (d == null || d.getWidth() <= 0 || d.getHeight() <= 0) return defaultCursor; BufferedImage out = new BufferedImage((int) d.getWidth(), (int) d.getHeight(), BufferedImage.TYPE_INT_ARGB); out.getGraphics().drawImage(image, 0, 0, null); return toolkit.createCustomCursor(out, new Point(x, y), name); }
From source file:Main.java
/** * Centers a given window on the screen. * /* ww w . j ava 2 s. c o m*/ * @param window * The window, frame or dialog */ public static void centerOnScreen(Window window) { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((d.getWidth() - window.getWidth()) / 2); int y = (int) ((d.getHeight() - window.getHeight()) / 2); window.setLocation(x, y); }
From source file:Main.java
public static void center(JFrame mainWindow) { Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - mainWindow.getWidth()) / 2); int y = (int) ((dimension.getHeight() - mainWindow.getHeight()) / 2); mainWindow.setLocation(x, y);/* w ww.j av a 2s . c o m*/ }
From source file:Main.java
public static Point getPointForCentering(Dialog dialog, Window parent) { Dimension size = dialog.getSize(); Dimension parentSize = parent.getSize(); int centerX = (int) ((parentSize.getWidth() - size.getWidth()) / 2 + parent.getX()); int centerY = (int) ((parentSize.getHeight() - size.getHeight()) / 2 + parent.getY()); return new Point(centerX, centerY); }
From source file:Main.java
public static void setLocationRelativeTo(Window child, Window parent) { Dimension d = parent.getSize(); Dimension u = child.getSize(); child.setLocation((int) ((d.getWidth() / 2) - (u.getWidth() / 2)), (int) ((d.getHeight() / 2) - (u.getHeight() / 2))); }
From source file:Main.java
public static void centerFrame(JFrame frame, Preferences prefs, int defWidth, int defHeight) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int w = (int) ((screenSize.getWidth() / 100) * defWidth); int h = (int) ((screenSize.getHeight() / 100) * defHeight); int x = (int) ((screenSize.getWidth() - w) / 2); int y = (int) ((screenSize.getHeight() - h) / 2); if (prefs != null) { frame.setBounds(prefs.getInt("x", x), prefs.getInt("y", y), prefs.getInt("w", w), prefs.getInt("h", h)); } else {/*from w w w.j a v a2s . c o m*/ frame.setBounds(x, y, w, h); } }
From source file:Main.java
/** * Centers a component on screen./*from w ww. ja va 2 s. com*/ * * @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
/** * Displays a message dialog with given information. *//*from ww w.j a v a 2s. com*/ 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
/** * Sets the size of the window to a width and height factor of the screen size. * // ww w .j a v a 2s .c o m * @param window The window to set the size. * @param widthFactor The width factor of the screen size. * @param heightFactor The height factor of the screen size. */ public static void setSize(Window window, double widthFactor, double heightFactor) { Dimension screenSize = getScreenSize(window); int width = (int) (screenSize.getWidth() * widthFactor); int height = (int) (screenSize.getHeight() * heightFactor); window.setSize(width, height); }