Java JFrame putOnWidestScreen(JFrame frame)

Here you can find the source of putOnWidestScreen(JFrame frame)

Description

put On Widest Screen

License

Apache License

Parameter

Parameter Description
frame a parameter

Declaration

public static void putOnWidestScreen(JFrame frame) 

Method Source Code


//package com.java2s;
/*//  ww  w.  ja  va  2  s  . c o m
 *
 *  Copyright (c) 2015 University of Massachusetts
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you
 *  may not use this file except in compliance with the License. You
 *  may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 *  implied. See the License for the specific language governing
 *  permissions and limitations under the License.
 *
 *  Initial developer(s): Westy
 *
 */

import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import javax.swing.JFrame;

public class Main {
    /**
     *
     * @param frame
     */
    public static void putOnWidestScreen(JFrame frame) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] gs = ge.getScreenDevices();
        int widestGD = -1;
        int widestGC = -1;
        double widestSize = 0;
        for (int j = 0; j < gs.length; j++) {
            GraphicsDevice gd = gs[j];
            GraphicsConfiguration[] gcs = gd.getConfigurations();
            for (int i = 0; i < gcs.length; i++) {
                Rectangle gcBounds = gcs[i].getBounds();
                System.out.println(gcBounds);
                if (gcBounds.getWidth() > widestSize) {
                    widestGD = j;
                    widestGC = i;
                    widestSize = gcBounds.getWidth();
                }
            }
        }
        if (widestSize > 0) {
            GraphicsDevice gd = gs[widestGD];
            GraphicsConfiguration[] gcs = gd.getConfigurations();
            GraphicsConfiguration gc = gcs[widestGC];
            frame.setBounds(gc.getBounds());
        } else {
            throw new RuntimeException("No Screens Found");
        }
    }
}

Related

  1. packFrame(JFrame frame)
  2. packJFrameWindow(final JComponent comp)
  3. POPUP(JFrame frame, String message)
  4. popupError(JFrame parent, String title, String text)
  5. position(JFrame f)
  6. refreshShape(final JFrame frame)
  7. registerCloseAction(final JFrame dialog, KeyStroke keyStroke)
  8. registerMenuShortcut(String uniqueActionName, Action action, int keyCode, JFrame frame)
  9. renderDialog(JFrame theframe, String szMessage, int noffsetx, int noffsety)