Example usage for java.awt Frame MAXIMIZED_BOTH

List of usage examples for java.awt Frame MAXIMIZED_BOTH

Introduction

In this page you can find the example usage for java.awt Frame MAXIMIZED_BOTH.

Prototype

int MAXIMIZED_BOTH

To view the source code for java.awt Frame MAXIMIZED_BOTH.

Click Source Link

Document

This state bit mask indicates that frame is fully maximized (that is both horizontally and vertically).

Usage

From source file:Main.java

public static void maximize(Frame frame) {
    int state = frame.getExtendedState();

    // Set the maximized bits
    state |= Frame.MAXIMIZED_BOTH;

    // Maximize the frame
    frame.setExtendedState(state);/*from w  w w  .  ja  v a2  s. c o m*/
}

From source file:Main.java

public static void minimize(Frame frame) {
    int state = frame.getExtendedState();

    // Clear the maximized bits
    state &= ~Frame.MAXIMIZED_BOTH;

    // Maximize the frame
    frame.setExtendedState(state);/*from   ww  w.j a v  a2 s .c  o  m*/
}

From source file:Main.java

public static final void fullScreen(Frame frame) {
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
}

From source file:Main.java

public static void main() {

    Frame frame = new Frame();

    WindowStateListener listener = new WindowAdapter() {
        public void windowStateChanged(WindowEvent evt) {
            int oldState = evt.getOldState();
            int newState = evt.getNewState();

            if ((oldState & Frame.ICONIFIED) == 0 && (newState & Frame.ICONIFIED) != 0) {
                System.out.println("Frame was iconized");
            } else if ((oldState & Frame.ICONIFIED) != 0 && (newState & Frame.ICONIFIED) == 0) {
                System.out.println("Frame was deiconized");
            }//from w  ww  .  ja  v a2 s .  co  m

            if ((oldState & Frame.MAXIMIZED_BOTH) == 0 && (newState & Frame.MAXIMIZED_BOTH) != 0) {
                System.out.println("Frame was maximized");
            } else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_BOTH) == 0) {
                System.out.println("Frame was minimized");
            }
        }
    };

    frame.addWindowStateListener(listener);
    frame.setVisible(true);
}

From source file:Main.java

static void createFrameAtLocation(Point p) {
    JFrame frame = new JFrame();
    frame.setTitle("Test frame on two screens");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());
    JTextArea textareaA = new JTextArea(24, 80);
    textareaA.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1));
    panel.add(textareaA, BorderLayout.CENTER);
    frame.setLocation(p);/*  ww w .j  av  a 2 s  . c  o m*/
    frame.add(panel);
    frame.pack();
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    frame.setVisible(true);
}

From source file:Main.java

/**
 * Mostra uma caixa de menssagem para que seja ensirido um valor.
 * @param frame//from   www.  j a  v a2 s  .  co m
 * @param texto
 * @param title
 * @param valorInicial
 * @param type
 * @return
 * @author Thiago Benega
 * @since 13/04/2009
 */
public static String showTextboxDialog(javax.swing.JFrame frame, String texto, String title,
        String valorInicial, int type) {
    Object txt = null;
    JDialog jDialog = new JDialog();
    jDialog.setTitle(title);
    jDialog.setFocusableWindowState(true);

    if (frame != null) {
        frame.setExtendedState(Frame.ICONIFIED);
        frame.pack();
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    }

    switch (type) {
    case JOptionPane.OK_CANCEL_OPTION:
        txt = JOptionPane.showInputDialog(jDialog, texto, title, type, null, null, valorInicial);//.toString();
        break;
    case JOptionPane.YES_NO_OPTION:
        txt = JOptionPane.showConfirmDialog(jDialog, texto, title, type, JOptionPane.INFORMATION_MESSAGE);
        break;
    default:
        JOptionPane.showMessageDialog(jDialog, texto, title, type);
        break;
    }

    jDialog = null;
    return txt != null ? txt.toString() : null;

}

From source file:Main.java

/**
 * Maximumiz both./*from  ww  w  .j  av  a  2 s.c  om*/
 *
 * @param window
 *            the window
 */
public static void maximumizBoth(final Window window) {
    if (window instanceof Frame) {
        final Frame frm = (Frame) window;
        frm.setExtendedState(Frame.MAXIMIZED_BOTH);
    } else {
        window.setSize(Toolkit.getDefaultToolkit().getScreenSize());
    }

}

From source file:Main.java

/**
 * Gets the window actual size.//w  ww.  ja v  a  2 s  . co  m
 *
 * @param window
 *            the window
 * @return the window actual size
 */
public static Dimension getWindowActualSize(final Window window) {
    if (window.isVisible()) {
        return window.getSize();
    }
    if (window instanceof Frame) {
        final Frame frame = (Frame) window;
        if (frame.getExtendedState() == Frame.MAXIMIZED_BOTH) {
            return Toolkit.getDefaultToolkit().getScreenSize();
        }
    }
    return window.getSize();
}

From source file:Main.java

/**
 * Maximizes a JFrame, just like the 'maximize window' button does.
 * <p>//from   ww w . jav  a 2  s.  co m
 * @param f     The frame to maximize.
 */
public static void maximizeJFrame(JFrame f) {

    f.setExtendedState(Frame.MAXIMIZED_BOTH);
}

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/*from  w  w w  . ja v a2 s  . com*/
 */
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();
}