Java Utililty Methods Screen Size

List of utility methods to do Screen Size

Description

The list of methods to do Screen Size are organized into topic(s).

Method

RectanglegetDesktopBounds()
Return the entire desktop bounds (take multi screens in account)
Rectangle result = new Rectangle();
final GraphicsDevice[] gs = getLocalGraphicsEnvironment().getScreenDevices();
for (int j = 0; j < gs.length; j++)
    result = result.union(gs[j].getDefaultConfiguration().getBounds());
return result;
RectanglegetDesktopBounds()
get the bounds of the users desktop...
Rectangle virtualBounds = new Rectangle();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
for (int j = 0; j < gs.length; j++) {
    GraphicsDevice gd = gs[j];
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    Rectangle rect = gc.getBounds();
    if (rect != null)
...
RectanglegetLocalScreenBounds()
Gets the local monitor's screen bounds.
GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
return e.getMaximumWindowBounds();
RectanglegetLocationFromMouse(Dimension panelPrefSize_)
get Location From Mouse
GraphicsDevice device = MouseInfo.getPointerInfo().getDevice();
Dimension screensize = new Dimension(device.getDisplayMode().getWidth(),
        device.getDisplayMode().getHeight());
int x = (screensize.width - panelPrefSize_.width) / 2;
int y = (screensize.height - panelPrefSize_.height) / 2;
return new Rectangle(x, y, panelPrefSize_.width, panelPrefSize_.height);
RectanglegetMaximumWindowBounds()
Computes the maximum bounds of the current screen device.
try {
    final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    return localGraphicsEnvironment.getMaximumWindowBounds();
} catch (Exception e) {
final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
return new Rectangle(0, 0, s.width, s.height);
RectanglegetMaximumWindowBounds()
get Maximum Window Bounds
final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
    final Method method = GraphicsEnvironment.class.getMethod("getMaximumWindowBounds", (Class[]) null);
    return (Rectangle) method.invoke(localGraphicsEnvironment, (Object[]) null);
} catch (Exception e) {
final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
return new Rectangle(0, 0, s.width, s.height);
...
intgetMaximumWindowWidth()
get Maximum Window Width
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension dim = toolkit.getScreenSize();
return dim.width;
DimensiongetMaxSize(Window frame)
get Max Size
Toolkit toolkit = Toolkit.getDefaultToolkit();
GraphicsConfiguration config = frame.getGraphicsConfiguration();
Dimension availableScreenSize = new Dimension(toolkit.getScreenSize());
Insets insets = toolkit.getScreenInsets(config);
availableScreenSize.width -= (insets.left + insets.right);
availableScreenSize.height -= (insets.top + insets.bottom);
return availableScreenSize;
DimensiongetMaxUsableScreenSize()
get Max Usable Screen Size
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
screenSize.width = Math.min(screenSize.width, GraphicsEnvironment.getLocalGraphicsEnvironment()
        .getDefaultScreenDevice().getDisplayMode().getWidth());
screenSize.height -= 48;
return screenSize;
DimensiongetMaxWindowSize()
Gets the max window size.
final Dimension d = getScreenDimesion();
return new Dimension((int) d.getWidth() - 100, (int) d.getHeight() - 100);