Here you can find the source of putOnWidestScreen(JFrame frame)
Parameter | Description |
---|---|
frame | a parameter |
public static void putOnWidestScreen(JFrame frame)
//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"); } } }