List of usage examples for javax.swing JFrame getHeight
public int getHeight()
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 w w . j av a2 s.c o m }
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 . j a v a2s . com*/ }
From source file:Main.java
public static void showFrame(JFrame frame, JFrame parent) { frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.pack();/*from w ww .j av a 2s. c om*/ 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. ja va2 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 . j a 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(); }
From source file:Main.java
public static void centerFrame(JFrame frame) { GraphicsDevice defaultScreen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); Rectangle screenSize = defaultScreen.getDefaultConfiguration().getBounds(); int midx = screenSize.width / 2; int midy = screenSize.height / 2; int posx = midx - (frame.getWidth() / 2); int posy = midy - (frame.getHeight() / 2); frame.setLocation(posx, posy);/*from w w w . j a va 2 s .com*/ }
From source file:QandE.MyDemo1.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*w w w .jav a 2 s .c o m*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("MyDemo1"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add a label with bold italic font. JLabel label = new JLabel("My Demo"); frame.getContentPane().add(BorderLayout.CENTER, label); if (true) { label.setFont(label.getFont().deriveFont(Font.ITALIC | Font.BOLD)); } else { //another way of doing it, but not as appropriate since //setFont is faster than using HTML. label.setText("<html><i>My Demo</i></html>"); } label.setHorizontalAlignment(JLabel.CENTER); //Display the window, making it a little bigger than it really needs to be. frame.pack(); frame.setSize(frame.getWidth() + 100, frame.getHeight() + 50); frame.setVisible(true); }
From source file:QandE.MyDemo2.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from w ww .j a v a 2s . co m*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("MyDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenu menu = new JMenu("Menu"); JMenuBar mb = new JMenuBar(); mb.add(menu); frame.setJMenuBar(mb); //Add a label with bold italic font. JLabel label = new JLabel("My Demo"); frame.getContentPane().add(BorderLayout.CENTER, label); if (true) { label.setFont(label.getFont().deriveFont(Font.ITALIC | Font.BOLD)); } else { //another way of doing it, but not as appropriate since //setFont is faster than using HTML. label.setText("<html><i>My Demo</i></html>"); } label.setHorizontalAlignment(JLabel.CENTER); //Display the window, making it a little bigger than it really needs to be. frame.pack(); frame.setSize(frame.getWidth() + 100, frame.getHeight() + 50); frame.setVisible(true); }
From source file:QandE.MyDemo3.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from w w w .j a va2 s . c om*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("MyDemo3"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add a label with bold italic font. JLabel label = new JLabel("My Demo"); frame.getContentPane().add(BorderLayout.CENTER, label); if (true) { label.setFont(label.getFont().deriveFont(Font.ITALIC | Font.BOLD)); } else { //another way of doing it, but not as appropriate since //setFont is faster than using HTML. label.setText("<html><i>My Demo</i></html>"); } label.setHorizontalAlignment(JLabel.CENTER); JButton b = new JButton("A button"); frame.getContentPane().add(BorderLayout.PAGE_END, b); frame.getRootPane().setDefaultButton(b); //Display the window, making it a little bigger than it really needs to be. frame.pack(); frame.setSize(frame.getWidth() + 100, frame.getHeight() + 50); frame.setVisible(true); }