private static int getFontSize() { if (Toolkit.getDefaultToolkit().getScreenResolution() >= 110) { // Rely on DPI if it is a high value. return Toolkit.getDefaultToolkit().getScreenResolution() / 7 + 1; } else { // Otherwise try to guess it from the monitor size: // If the width is wider than Full HD (1080p, or 1920x1080), then assume it's high-DPI. GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); if (ge.getMaximumWindowBounds().getWidth() > 4096) { return 56; } else if (ge.getMaximumWindowBounds().getWidth() > 2048) { return 28; } else { return 14; } } }
import java.awt.*; import javax.swing.*; public class Test extends JFrame { public Test() { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); this.setMaximizedBounds(env.getMaximumWindowBounds()); this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH); } public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); Test t = new Test(); t.setVisible(true); } }
public static int GetScreenWorkingWidth() { return java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().width; } public static int GetScreenWorkingHeight() { return java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height; }
protected Rectangle screenSize() { return GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); }
/** * Returns the screen coordinates for the monitor that contains the * specified point. This is useful for setups with multiple monitors, * to ensure that popup windows are positioned properly. * * @param x The x-coordinate, in screen coordinates. * @param y The y-coordinate, in screen coordinates. * @return The bounds of the monitor that contains the specified point. */ public static Rectangle getScreenBoundsForPoint(int x, int y) { GraphicsEnvironment env = GraphicsEnvironment. getLocalGraphicsEnvironment(); GraphicsDevice[] devices = env.getScreenDevices(); for (int i=0; i<devices.length; i++) { GraphicsConfiguration[] configs = devices[i].getConfigurations(); for (int j=0; j<configs.length; j++) { Rectangle gcBounds = configs[j].getBounds(); if (gcBounds.contains(x, y)) { return gcBounds; } } } // If point is outside all monitors, default to default monitor (?) return env.getMaximumWindowBounds(); }
void restoreDefaults() { // f.setSize(f.getWidth(), getDesktopRect(f.getGraphicsConfiguration()).height); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = env.getMaximumWindowBounds(); f.setSize(f.getWidth(), bounds.height); f.validate(); sp.setDividerLocation(sp.getSize().height - 100); // Does not work on first button press }
public static Rectangle getWorkSpaceBounds() { // @todo deal with default when multi-monitor return GraphicsEnvironment.getLocalGraphicsEnvironment() .getMaximumWindowBounds(); }
private Rectangle getWorkSpaceBounds() { return GraphicsEnvironment.getLocalGraphicsEnvironment() .getMaximumWindowBounds(); }
import java.awt.GraphicsEnvironment; import java.awt.Rectangle; public class ScreenResolution { public static void main(String[] args) { Rectangle r = GraphicsEnvironment.getLocalGraphicsEnvironment() .getMaximumWindowBounds(); System.out.println(r); } }
public static Dimension getMaximumWindowDimension() { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = env.getMaximumWindowBounds(); //System.out.println("bounds:" + bounds.width + " " + bounds.height); return new Dimension(bounds.width, bounds.height); }
public static Rectangle getNewFallbackFrameBounds( ) { Rectangle screenBounds = getLocalGraphicsEnvironment( ).getMaximumWindowBounds( ); float fracOfScreen = 0.85f; int width = round( fracOfScreen * screenBounds.width ); int height = round( fracOfScreen * screenBounds.height ); int x = screenBounds.x + ( ( screenBounds.width - width ) / 2 ); int y = screenBounds.y + ( ( screenBounds.height - height ) / 2 ); return new Rectangle( x, y, width, height ); }
private static void giveFrameHalfScreen(final JFrame frame) { final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final Rectangle winSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); final int taskBarHeight = screenSize.height - winSize.height; final int width = (int) (screenSize.width * 0.505); final int height = screenSize.height - taskBarHeight; frame.setSize(width, height); } }
private Dimension getBoundingSize(Component source) { if (source instanceof Window) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = env.getMaximumWindowBounds(); return new Dimension(bounds.width, bounds.height); } else { return source.getParent().getSize(); } } }
private WidgetScreenResolutionAdjuster() { highDpiThreshold = SystemProperties.getInt("datacleaner.highdpi.threshold", 1600); if (GraphicsEnvironment.isHeadless()) { width = highDpiThreshold; } else { final GraphicsEnvironment graphicsEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); width = (int) graphicsEnv.getMaximumWindowBounds().getWidth(); } }
private Dimension getBoundingSize(Component source) { if (source instanceof Window) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = env.getMaximumWindowBounds(); return new Dimension(bounds.width, bounds.height); } else { return source.getParent().getSize(); } }
protected MasterFrame( boolean screenMenuBar ) { super( screenMenuBar ); // System.out.println( "screenMenuBar = " + screenMenuBar ); setBounds( GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds() ); }
public Rectangle getWindowSpace() { if( masterFrame != null ) { return new Rectangle( 0, 0, masterFrame.getWidth(), masterFrame.getHeight() ); } else { return GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); } }
/** Center the given {@link Window} on the default screen. */ public static void centerOnScreen(Window window) { Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); Rectangle max = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); int x = Math.max(center.x - Math.round(window.getWidth()/2f), max.x); int y = Math.max(center.y - Math.round(window.getHeight()/2f), max.y); window.setLocation(new Point(x, y)); }
public static void maxItWidth(JFrame jFrame) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle r = env.getMaximumWindowBounds(); Dimension d = r.getSize(); d.setSize(d.width, Math.min(d.height, jFrame.getPreferredSize().height)); jFrame.setSize(d); jFrame.setPreferredSize(d); }
public void offset(int offset) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = env.getMaximumWindowBounds(); int x = bounds.width - frame.getWidth() - 5; int y = bounds.height - frame.getHeight() - 5 - (frame.getHeight() + 5) * offset; frame.setLocation(x, y); } public void show() {