List of usage examples for java.awt Toolkit getDefaultToolkit
public static synchronized Toolkit getDefaultToolkit()
From source file:Main.java
public static void centerOnScreen(Window w, Window parent) { Rectangle r = new Rectangle(); if (parent == null) { r.setSize(Toolkit.getDefaultToolkit().getScreenSize()); } else {// w w w . j a v a2 s . c o m r.setLocation(parent.getLocation()); r.setSize(parent.getSize()); } // Determine the new location of the alert int x = r.x + (r.width - w.getWidth()) / 2; int y = r.y + (r.height - w.getHeight()) / 2; // Move the alert w.setLocation(x, y); }
From source file:Main.java
/** * Center JFrame./*from w w w . j a v a 2 s .com*/ */ public static void center(JFrame frame) { Dimension frameSize = frame.getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((screenSize.width - frameSize.width) >> 1, (screenSize.height - frameSize.height) >> 1); }
From source file:codeswarm.ui.MainView.java
/** * This is the main entry-point. It sets the native Look&Feel, creates and * shows the MainView./*ww w . j a v a2 s . c o m*/ * @param args the command line arguments. The first parameter * will be passed to {@link code_swarm}. It specifies the config-file. */ public static void main(final String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { Toolkit.getDefaultToolkit().setDynamicLayout(true); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { logger.warn("Trouble loading system look and feel. No biggie...", e); } new MainView(args).setVisible(true); } }); }
From source file:Main.java
public static void centerComponent(Component relativeTo, Component toCenter) { if (relativeTo == null) { Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); int screenHeight = screenSize.height; int screenWidth = screenSize.width; toCenter.setLocation((screenWidth / 2) - (toCenter.getSize().width / 2), (screenHeight / 2) - (toCenter.getSize().height / 2)); } else {/* w ww. j a v a 2 s .co m*/ Point loc = relativeTo.getLocationOnScreen(); Rectangle bounds = relativeTo.getBounds(); toCenter.setLocation((int) (loc.x + bounds.getWidth() / 2) - (toCenter.getWidth() / 2), (int) (loc.y + bounds.getHeight() / 2) - (toCenter.getHeight() / 2)); } }
From source file:Main.java
/** * Centers a given window on the screen. * //from ww w . j a va2 s. c om * @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 centerFrame(final Window frame) { final Rectangle bounds = frame.getBounds(); final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); bounds.x = (screen.width / 2) - (bounds.width / 2); bounds.y = (screen.height / 2) - (bounds.height / 2); frame.setBounds(bounds);/*from w w w.j a v a 2 s. c o m*/ }
From source file:Main.java
public static void center(Window frame, int left, int right, int top, int bottom) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > (screenSize.height - top - bottom)) { frameSize.height = screenSize.height - top - bottom; }/* w w w . j a v a2s . c om*/ if (frameSize.width > screenSize.width - left - right) { frameSize.width = screenSize.width - left - right; } if (!frameSize.equals(frame.getSize())) { frame.setSize(frameSize); } frame.setLocation(left + (screenSize.width - frameSize.width) / 2, top + (screenSize.height - frameSize.height) / 2); }
From source file:Main.java
/** * Centraliza a janela na tela// w w w . j a va 2 s . c o m * @param w janela a ser centralizada */ public static void center(Window w) { Dimension us = w.getSize(), them = Toolkit.getDefaultToolkit().getScreenSize(); int newX = (them.width - us.width) / 2; int newY = (them.height - us.height) / 2; w.setLocation(newX, newY); }
From source file:Main.java
public static void centerOnScreen(Component aCompo, Dimension aCompoSize) { final Dimension lScreenSize = Toolkit.getDefaultToolkit().getScreenSize(); aCompo.setLocation(lScreenSize.width / 2 - (aCompoSize.width / 2), lScreenSize.height / 2 - (aCompoSize.height / 2)); }
From source file:Main.java
public static void centerWithinScreen(final Window wind) { if (wind == null) { return;//from w ww. j av a 2 s .com } final Toolkit toolKit = Toolkit.getDefaultToolkit(); final Rectangle rcScreen = new Rectangle(toolKit.getScreenSize()); final Dimension windSize = wind.getSize(); final Dimension parentSize = new Dimension(rcScreen.width, rcScreen.height); if (windSize.height > parentSize.height) { windSize.height = parentSize.height; } if (windSize.width > parentSize.width) { windSize.width = parentSize.width; } center(wind, rcScreen); }