Example usage for java.awt GraphicsEnvironment getMaximumWindowBounds

List of usage examples for java.awt GraphicsEnvironment getMaximumWindowBounds

Introduction

In this page you can find the example usage for java.awt GraphicsEnvironment getMaximumWindowBounds.

Prototype

public Rectangle getMaximumWindowBounds() throws HeadlessException 

Source Link

Document

Returns the maximum bounds for centered Windows.

Usage

From source file:Main.java

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    System.out.println(ge.getMaximumWindowBounds());

}

From source file:Main.java

public static void main(String[] args) {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle bounds = env.getMaximumWindowBounds();
    System.out.println("Screen Bounds: " + bounds);

    GraphicsDevice screen = env.getDefaultScreenDevice();
    GraphicsConfiguration config = screen.getDefaultConfiguration();
    System.out.println("Screen Size  : " + config.getBounds());

    JFrame frame = new JFrame("Frame Info");
    System.out.println("Frame Insets : " + frame.getInsets());

    frame.setSize(200, 200);//from  w ww .j ava2 s . c o  m
    System.out.println("Frame Insets : " + frame.getInsets());
    frame.setVisible(true);

    System.out.println("Frame Size   : " + frame.getSize());
    System.out.println("Frame Insets : " + frame.getInsets());
    System.out.println("Content Size : " + frame.getContentPane().getSize());
}

From source file:com.itemanalysis.jmetrik.gui.Jmetrik.java

public static void main(String args[]) {

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                Color SELECTED_COLOR = new Color(184, 204, 217);
                Color BASE_COLOR = new Color(220, 231, 243, 50);
                Color ALT_COLOR = new Color(220, 231, 243, 115);

                //                    Insets MENU_INSETS = new Insets(1,12,2,5);//default values
                //                    Font MENU_FONT = new Font("SansSerif ", Font.PLAIN, 12);//default values

                //                    UIManager.put("nimbusBase", BASE_COLOR);
                UIManager.put("nimbusSelection", SELECTED_COLOR);
                UIManager.put("nimbusSelectionBackground", SELECTED_COLOR);
                UIManager.put("Menu[Enabled+Selected].backgroundPainter", SELECTED_COLOR);

                //override defaults
                for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                    if (info.getName().equals("Nimbus")) {
                        UIManager.setLookAndFeel(info.getClassName());
                        UIDefaults defaults = UIManager.getLookAndFeelDefaults();
                        defaults.put("Table.gridColor", Color.lightGray);
                        defaults.put("Table.disabled", false);
                        defaults.put("Table.showGrid", true);
                        defaults.put("Table.intercellSpacing", new Dimension(1, 1));
                        break;
                    }/*from  w ww  .  j a v a 2s  .  c  o  m*/
                }

                //                    UIManager.put("TitledBorder.position", TitledBorder.TOP);

                //                    UIManager.put("Table.showGrid", true);
                //                    UIManager.put("Table.gridColor", Color.RED);
                //                    UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
            } catch (UnsupportedLookAndFeelException ulafe) {
                //                    logger.fatal("Substance failed to set", ulafe);
            } catch (Exception ex) {
                //                    logger.fatal(ex.getMessage(), ex);
            }

            JFrame frame = new Jmetrik();

            //            set window to maximum size but account for taskbar
            GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
            Rectangle rect = env.getMaximumWindowBounds();
            int width = Double.valueOf(rect.getWidth() - 1.0).intValue();
            int height = Double.valueOf(rect.getHeight() - 1.0).intValue();
            frame.setMaximizedBounds(new Rectangle(0, 0, width, height));
            frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            frame.pack();
            //            frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
            frame.setVisible(true);

            //check for updates to jmetrik
            ((Jmetrik) frame).checkForUpdates();
        }
    });

}

From source file:Main.java

/**
 * @return ScreenDimantions excluding toolbar 
 *///from w w w.  j a v  a2  s  .  c om
public static Rectangle availableScreenSize() {

    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();

    // get maximum window bounds
    return graphicsEnvironment.getMaximumWindowBounds();

}

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  ww .ja v  a  2s .  co 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

/**
 * @param r//from   w w w.  j  a  v  a  2s. co m
 *          the original rectangle
 * @param includeReservedInsets
 *          if taskbar and other windowing insets should be included in the
 *          returned area
 * @return iff there are multiple monitors the other monitor than the
 *         effective view of the monitor that the rectangle mostly coveres, or
 *         null if there is just one screen
 */
public static Rectangle getOppositeFullScreenBoundsFor(Rectangle r, boolean includeReservedInsets) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    TreeMap<Integer, Rectangle> prioMap = new TreeMap<Integer, Rectangle>();
    for (GraphicsDevice dev : ge.getScreenDevices()) {
        Rectangle bounds;
        if ((!includeReservedInsets) && dev == ge.getDefaultScreenDevice()) {
            bounds = ge.getMaximumWindowBounds();
        } else {
            bounds = dev.getDefaultConfiguration().getBounds();
        }
        Rectangle intersection = bounds.intersection(r);
        prioMap.put(intersection.width * intersection.height, bounds);
    }
    if (prioMap.size() <= 1) {
        return null;
    } else {
        return prioMap.get(prioMap.firstKey());
    }
}

From source file:Main.java

/**
 * Used for getting the actual bound of the monitor that contains Point p
 *
 * @param p - point to check monitor for
 * @return - current monitor bounds//from  w ww  .j a  va  2s. c  om
 */
public static Rectangle getScreenBoundsForPoint(Point p) {
    Rectangle bounds;
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

    GraphicsConfiguration graphicsConfiguration = null;
    for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
        if (gd.getDefaultConfiguration().getBounds().contains(p)) {
            graphicsConfiguration = gd.getDefaultConfiguration();
            break;
        }
    }
    if (graphicsConfiguration != null) {
        bounds = graphicsConfiguration.getBounds();
        Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfiguration);
        bounds.x += screenInsets.left;
        bounds.y += screenInsets.top;
        bounds.height -= screenInsets.bottom;
        bounds.width -= screenInsets.right;
    } else {
        bounds = env.getMaximumWindowBounds();
    }
    return (bounds);
}

From source file:com.game.ui.views.MapEditor.java

public void generateGUI() throws IOException {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    //        setResizable(false);
    JMenuBar menubar = new JMenuBar();
    ImageIcon icon = null;/*  w  w  w  . j  a v a 2s.  c o  m*/
    try {
        icon = GameUtils.shrinkImage("save.png", 20, 20);
    } catch (IOException e) {
        System.out.println("Dialog : showDialogForMap(): Exception occured :" + e);
        e.printStackTrace();
    }
    JMenu file = new JMenu("File");
    JMenuItem save = new JMenuItem("Save", icon);
    save.setToolTipText("Save Map Information");
    save.setActionCommand("Save Map");
    save.addActionListener(this);
    file.add(save);
    menubar.add(file);
    setJMenuBar(menubar);
    JPanel topPanel = new JPanel();
    topPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    topPanel.setLayout(new GridBagLayout());
    JLabel headerLbl = new JLabel("Legend : ");
    headerLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    JLabel lbl1 = new JLabel();
    lbl1.setPreferredSize(new Dimension(50, 20));
    lbl1.setBackground(Configuration.pathColor);
    lbl1.setOpaque(true);
    JLabel lbl2 = new JLabel("- Represents the path.");
    JLabel lbl3 = new JLabel();
    lbl3.setPreferredSize(new Dimension(50, 20));
    lbl3.setBackground(Configuration.enemyColor);
    lbl3.setOpaque(true);
    JLabel lbl4 = new JLabel("- Represents the path with monsters");
    JLabel lbl5 = new JLabel();
    lbl5.setPreferredSize(new Dimension(50, 20));
    lbl5.setBackground(Configuration.startPointColor);
    lbl5.setOpaque(true);
    JLabel lbl6 = new JLabel("- Represents the starting point in the path");
    JLabel lbl7 = new JLabel();
    lbl7.setBackground(Configuration.endPointColor);
    lbl7.setOpaque(true);
    lbl7.setPreferredSize(new Dimension(50, 20));
    JLabel lbl8 = new JLabel("- Ending point in the path");
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.insets = new Insets(5, 5, 5, 5);
    c.gridwidth = 2;
    topPanel.add(headerLbl, c);
    c.fill = GridBagConstraints.NONE;
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.ipadx = 5;
    c.ipady = 5;
    topPanel.add(lbl1, c);
    c.gridx = 1;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    topPanel.add(lbl2, c);
    c.gridx = 0;
    c.gridy = 2;
    topPanel.add(lbl3, c);
    c.gridx = 1;
    topPanel.add(lbl4, c);
    c.gridx = 0;
    c.gridy = 3;
    topPanel.add(lbl5, c);
    c.gridx = 1;
    topPanel.add(lbl6, c);
    c.gridx = 0;
    c.gridy = 4;
    topPanel.add(lbl7, c);
    c.gridx = 1;
    topPanel.add(lbl8, c);
    add(topPanel, BorderLayout.NORTH);
    bottomPanel = new JPanel();
    add(bottomPanel, BorderLayout.CENTER);
    bottomPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    //        bottomPanel.add(new JButton("kaushik"));
    pack();
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    setMaximizedBounds(env.getMaximumWindowBounds());
    setVisible(true);
    callDialogForUsersInput();
}

From source file:com.game.ui.views.MapPanel.java

public void buildMap(MapInformation Map) throws IOException {
    getMapInformation(Map);/*from   ww  w.  jav  a2s  . c  o m*/
    mapPanel = new JPanel();
    mapPanel.setLayout(new GridLayout(mapRows, mapColumns));
    tile = new JButton[mapRows * mapColumns];
    commandCounter = 1;
    for (int x = 0; x < mapRows; x++) {
        for (int y = 0; y < mapColumns; y++) {
            tile[commandCounter - 1] = new JButton();
            (tile[commandCounter - 1]).setActionCommand("" + commandCounter);
            tile[commandCounter - 1].addActionListener(this);
            mapPanel.add(tile[commandCounter - 1]);
            tileInformation = pathMap.get(commandCounter);
            if (tileInformation != null) {
                mapPathPoints();
                if (tileInformation.isEndTile()) {
                    mapEndPoints();
                }
                if (tileInformation.isStartTile()) {
                    mapStartPoints();
                    numberofPlayers++;
                }
                if (tileInformation.getEnemy() != null) {
                    mapEnemyPoints(tileInformation);
                    numberofEnemys++;
                }
            }
            commandCounter++;
        }
    }
    UIManager.installLookAndFeel("SeaGlass", "com.seaglasslookandfeel.SeaGlassLookAndFeel");

    wrapperPanel.add(mapPanel, BorderLayout.CENTER);
    add(wrapperPanel);
    pack();
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    setMaximizedBounds(env.getMaximumWindowBounds());
    setVisible(true);
}