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

intgetMinimumCacheSize(int tileSize, double overdrawFactor)
Compute the minimum cache size for a view, using the size of the screen.
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
return (int) Math.max(4, Math.round((2 + screenSize.getWidth() * overdrawFactor / tileSize)
        * (2 + screenSize.getHeight() * overdrawFactor / tileSize)));
DimensiongetSizeWithScreen(double xd, double yd)
get Size With Screen
Dimension d = getScreenSize();
double width = d.getWidth() * xd;
double height = d.getHeight() * yd;
d = new Dimension((int) width, (int) height);
return d;
doublegetSystemSizeRate()
get System Size Rate
return Toolkit.getDefaultToolkit().getScreenResolution() / DEFAULT_SCREEN_RESOLUTION;
DimensiongetWindowActualSize(final Window window)
Gets the window actual size.
if (window.isVisible()) {
    return window.getSize();
if (window instanceof Frame) {
    final Frame frame = (Frame) window;
    if (frame.getExtendedState() == Frame.MAXIMIZED_BOTH) {
        return Toolkit.getDefaultToolkit().getScreenSize();
return window.getSize();
ShapemakeEllipse(double x, double y, double size)
Return a Shape object for an "ellipse" symbol.
return new Ellipse2D.Double(x - size, y - size, size * 2, size * 2);
voidmaximizeWindowWithMargin(final Window window, final int margin, final Dimension maxSize)
Resizes a window by setting its bounds to maximum that fits inside the default screen having the specified margin around it, and centers the window on the screen.
GraphicsConfiguration gconfig = window.getGraphicsConfiguration();
if (gconfig == null)
    GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
final Rectangle bounds = gconfig.getBounds();
final Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gconfig);
final int width = bounds.width - insets.left - insets.right - margin * 2;
final int height = bounds.height - insets.top - insets.bottom - margin * 2;
if (maxSize == null)
...
DimensionscreenSize()
screen Size
return Toolkit.getDefaultToolkit().getScreenSize();
voidsetLocationRelativeToAndSizeToWindow(Component parent, Component child, Dimension max)
Sets the location of the specified child relative to the location of the specified parent and then makes it visible, and size to fill the window.
setLocationRelativeToAndSizeToWindow(parent.getBounds(), child, max);
voidsetSize(final Window window, final int minusX, final int minusY)
set Size
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final Dimension screenSize = toolkit.getScreenSize();
final double screenWidth = screenSize.getWidth();
final double screenHeight = screenSize.getHeight();
final Dimension size = new Dimension((int) (screenWidth - minusX), (int) (screenHeight - minusY));
window.setBounds(minusX / 2, minusY / 2, size.width, size.height);
window.setPreferredSize(size);
voidsetSize(Window window, double widthFactor, double heightFactor)
Sets the size of the window to a width and height factor of the screen size.
Dimension screenSize = getScreenSize(window);
int width = (int) (screenSize.getWidth() * widthFactor);
int height = (int) (screenSize.getHeight() * heightFactor);
window.setSize(width, height);