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

PointadjustPopupLocationToFitScreen(Component invoker, Dimension preferredSize, int xposition, int yposition)
adjust Popup Location To Fit Screen
Point p = new Point(xposition, yposition);
if (GraphicsEnvironment.isHeadless())
    return p;
Toolkit toolkit = Toolkit.getDefaultToolkit();
Rectangle screenBounds;
Insets screenInsets;
GraphicsConfiguration gc = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
...
StringformatScreenSize(Dimension screenSize)
format Screen Size
if (screenSize != null) {
    return String.format("%dx%d", screenSize.width, screenSize.height);
} else
    return "0x0";
intgetComponentWidthForResolution(int screenWidth, int desiredSize)
Returns a proportional width according to screenWidth and desiredSize for the current screen resolution
int currentScreenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
int result = desiredSize * currentScreenWidth / screenWidth;
return result;
DimensiongetDefaultAppSize()
get Default App Size
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
return new Dimension(4 * screenSize.width / 5, 4 * screenSize.height / 5);
DimensiongetDefaultDeviceScreenSize()
get Default Device Screen Size
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getScreenDevices()[0];
Dimension screenSize = gs.getDefaultConfiguration().getBounds().getSize();
return screenSize;
DimensiongetDefaultMainFrameSize()
get Default Main Frame Size
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
size.width = size.width * 8 / 10;
size.height = size.height * 8 / 10;
return size;
RectanglegetDefaultScreenBounds()
get Default Screen Bounds
return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration()
        .getBounds();
GraphicsDevicegetDefaultScreenDevice()
Return the default screen device.
try {
    return getLocalGraphicsEnvironment().getDefaultScreenDevice();
} catch (HeadlessException e) {
    return null;
DimensiongetDefaultScreenSize()
get Default Screen Size
Rectangle dimension = getDefaultScreenSizeWithoutAdjustment();
int noOfScreens = (int) Math.floor((double) dimension.width / (double) dimension.height); 
if (noOfScreens < 1) {
    noOfScreens = 1;
if (dimension.width < 100 || dimension.height < 100) {
    dimension.width = DEFAULT_SIZE.width;
    dimension.height = DEFAULT_SIZE.height;
...
RectanglegetDefaultScreenSizeWithoutAdjustment()
get Default Screen Size Without Adjustment
return getDefaultScreenSizeWithoutAdjustment(false);