Example usage for java.awt Toolkit getScreenSize

List of usage examples for java.awt Toolkit getScreenSize

Introduction

In this page you can find the example usage for java.awt Toolkit getScreenSize.

Prototype

public abstract Dimension getScreenSize() throws HeadlessException;

Source Link

Document

Gets the size of the screen.

Usage

From source file:tkwatch.Utilities.java

/**
 * Centers a frame on the screen; from Murach and Steelman, <i>Murach's Java
 * SE 6</i>, p. 487.// w  ww.jav a 2 s . c  o  m
 * 
 * @param window
 *            The window to center.
 */
public static final void centerWindow(final Window window) {
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final Dimension dimension = toolkit.getScreenSize();
    window.setLocation((dimension.width - window.getWidth()) / 2, (dimension.height - window.getHeight()) / 2);
}

From source file:storybook.toolkit.swing.SwingUtil.java

/**
 * Gets the dimension of the screen./*from  ww w .j a  va  2 s . c om*/
 *
 * @return the dimension of the screen
 */
public static Dimension getScreenSize() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension d = tk.getScreenSize();
    return d;
}

From source file:CenteredFrame.java

public CenteredFrame() {
    setTitle("CenteredFrame");
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*from   w w  w . ja v a  2 s.  com*/
        }
    });
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;
    setSize(screenWidth / 2, screenHeight / 2);
    setLocation(screenWidth / 4, screenHeight / 4);
}

From source file:Main.java

public Main() {
    setTitle("CenteredFrame");
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/* ww w .  j  a v  a2 s  .  co m*/
        }
    });
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;
    setSize(screenWidth / 2, screenHeight / 2);
    setLocation(screenWidth / 4, screenHeight / 4);
}

From source file:SizedFrameTest.java

public SizedFrame() {
    // get screen dimensions

    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;

    // set frame width, height and let platform pick screen location

    setSize(screenWidth / 2, screenHeight / 2);
    setLocationByPlatform(true);/*  w  w  w . jav  a2  s.  c  om*/

    // set frame icon and title

    Image img = kit.getImage("icon.gif");
    setIconImage(img);
    setTitle("SizedFrame");
}

From source file:org.championship.manager.license.LicenseDialog.java

private void prepareSize() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension screenSize = toolkit.getScreenSize();
    int height = (int) screenSize.getHeight();
    int width = (int) (height / 1.3);

    if (height > 650) {
        height = 600;/*from  w  w w. ja v a  2  s .c o  m*/
        width = (int) (height / 1.3);
    }

    setSize(new Dimension(width, height));
}

From source file:piilSource.Histogram.java

public Histogram(final String s, List<List<String>> list, Character meta) {
    super(s);/*from w w  w .  j  a v  a  2  s .  c om*/
    metaLabel = (meta.equals('M')) ? "beta" : "expression";
    histogramPanel = createDemoPanel(s, list, metaLabel);
    histogramPanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(histogramPanel);

    exportButton = new JButton("Export to image");
    exportButton.setPreferredSize(new Dimension(150, 30));
    closeButton = new JButton("Close");
    closeButton.setPreferredSize(new Dimension(150, 30));
    buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new FlowLayout());
    buttonsPanel.setBackground(Color.WHITE);
    buttonsPanel.add(exportButton);
    buttonsPanel.add(closeButton);

    exportButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent bc) {
            ExportDialog export = new ExportDialog();
            export.showExportDialog(chartFrame, "Export view as ...", histogramPanel,
                    "Histogram of the " + metaLabel + " values for all samples - " + s);
        }
    });
    closeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            chartFrame.dispose();
        }
    });

    chartFrame = new JFrame();
    chartFrame.setLayout(new BorderLayout());
    chartFrame.setSize(400, 100);
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension dim = tk.getScreenSize();
    int xPos = (dim.width / 2) - (chartFrame.getWidth() / 2);
    int yPos = (dim.height / 2) - (chartFrame.getHeight() / 2);
    chartFrame.setLocation(xPos, yPos);
    chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    chartFrame.add(histogramPanel, BorderLayout.CENTER);
    chartFrame.add(buttonsPanel, BorderLayout.SOUTH);
    chartFrame.setSize(800, 400);
    chartFrame.setVisible(true);

}

From source file:org.openstatic.irc.client.O5Client.java

public void centerWindow() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    final int WIDTH = screenSize.width;
    final int HEIGHT = screenSize.height;
    this.setSize(520, 340);
    this.setLocation(WIDTH / 4 - 260, HEIGHT / 2 - 170);
}

From source file:org.openstatic.irc.client.O5Client.java

public boolean isCentered() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    final int WIDTH = screenSize.width;
    final int HEIGHT = screenSize.height;
    if (this.getX() == ((WIDTH / 2) - (this.getWidth() / 2))
            && this.getY() == ((HEIGHT / 2) - (this.getHeight() / 2))) {
        return true;
    } else {/* w  ww .  j a  v  a 2s .c o m*/
        return false;
    }
}

From source file:vic.collaborativeClouds.forms.Login.java

/**
 * Creates new form Login//w  ww  .j  a  v a  2  s . c  o m
 */
public Login() {
    initComponents();
    //this.setExtendedState(Login.MAXIMIZED_BOTH);
    this.setAlwaysOnTop(true);

    setLayout(new BorderLayout());
    ImageLocator mImage = new ImageLocator();
    //System.err.println(mImage.login_dash);
    JLabel background = new JLabel(new ImageIcon(mImage.login_dash));
    this.add(background);
    background.setLayout(new FlowLayout());

    Toolkit tk = Toolkit.getDefaultToolkit();
    int xSize = ((int) tk.getScreenSize().getWidth());
    int ySize = ((int) tk.getScreenSize().getHeight());
    this.setSize(xSize, ySize);
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2);
    heading.setLocation((xSize / 2) - 100, (ySize / 4) - 100);
    username.setLocation((xSize / 2) - 150, (ySize / 4));
    password.setLocation((xSize / 2) - 150, (ySize / 4) + 50);
    login.setLocation((xSize / 2) - 150, (ySize / 4) + 100);
    cancel.setLocation((xSize / 2) + 120, (ySize / 4) + 100);
    username.setOpaque(false);

}