List of usage examples for javax.swing JFrame getWidth
public int getWidth()
From source file:Main.java
public static void moveToCenter(JFrame frame) { int windowWidth = frame.getWidth(); int windowHeight = frame.getHeight(); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenWidth = screenSize.width; int screenHeight = screenSize.height; frame.setLocation(screenWidth / 2 - windowWidth / 2, screenHeight / 2 - windowHeight / 2); }
From source file:Main.java
/** * Used to centre the dialogs.//from ww w . j a v a 2 s. co m */ public static void centreOnParent(final JDialog dialog, final JFrame frame) { int x = frame.getX(); x += (frame.getWidth() - dialog.getWidth()) / 2; int y = frame.getY(); y += (frame.getHeight() - dialog.getHeight()) / 2; dialog.setLocation(x, y); }
From source file:Main.java
private static void centerOn(JFrame f, GraphicsConfiguration gc) { Rectangle bounds = gc.getBounds(); int x = bounds.x + ((bounds.width - f.getWidth()) / 2); int y = bounds.y + ((bounds.height - f.getHeight()) / 2); f.setLocation(x, y);/*from ww w.j a v a 2 s . co m*/ }
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);/* www. j a va2 s. co m*/ }
From source file:Main.java
/** * Centers a {@link JFrame} on screen.//from w w w . j a v a 2s . c o m */ public static void centerFrameOnScreen(JFrame frame) { final Dimension position = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((position.width - frame.getWidth()) / 2, (position.height - frame.getHeight()) / 2); }
From source file:Main.java
public static void centerJFrame(JFrame jFrame) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension screenSize = toolkit.getScreenSize(); int x = (screenSize.width - jFrame.getWidth()) / 2; int y = (screenSize.height - jFrame.getHeight()) / 2; jFrame.setLocation(x, y);//from w w w . jav a2s.c o m }
From source file:Main.java
public static void showFrame(JFrame frame, JFrame parent) { frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.pack();/* ww w . jav a2 s .c o m*/ frame.setLocation(parent.getX() + (parent.getWidth() - frame.getWidth()) / 2, parent.getY() + (parent.getHeight() - frame.getHeight()) / 2); frame.setVisible(true); }
From source file:Main.java
public static void setFrameCenter(JFrame frame) { int screenWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth(); int screenHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight(); frame.setLocation((screenWidth - frame.getWidth()) / 2, (screenHeight - frame.getHeight()) / 2); }
From source file:Main.java
public static void window_centered(JFrame frame) { frame.pack();//w w w.jav a 2 s. c o m Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int width = screenSize.width; int height = screenSize.height; int x = (width - frame.getWidth()) / 2; int y = (height - frame.getHeight()) / 2; frame.setLocation(x, y); }
From source file:Main.java
/** * Centers the frame on the screen and sets its bounds. THis method should be * used after you call frame.pack() or frame.setSize(). * @param frame//w w w . ja va 2 s .c o m */ public static void centerFrame(JFrame frame) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Point center = ge.getCenterPoint(); Rectangle bounds = ge.getMaximumWindowBounds(); int w = Math.max(bounds.width / 2, Math.min(frame.getWidth(), bounds.width)); int h = Math.max(bounds.height / 2, Math.min(frame.getHeight(), bounds.height)); int x = center.x - w / 2, y = center.y - h / 2; frame.setBounds(x, y, w, h); if ((w == bounds.width) && (h == bounds.height)) { frame.setExtendedState(Frame.MAXIMIZED_BOTH); } frame.validate(); }