List of utility methods to do JFrame Size
void | adaptSize(JFrame frame, int preferredWidth, int preferredHeight) Set the size of the frame to the given size, or the size of the screen if it the screen is too small. java.awt.Toolkit toolkit = frame.getToolkit(); Dimension sSize = toolkit.getScreenSize(); if (preferredWidth > 0 && preferredHeight > 0) { frame.setSize(Math.min(preferredWidth, sSize.width - 30), Math.min(preferredHeight, sSize.height - 30)); if (preferredWidth > sSize.width && preferredHeight > sSize.height) { frame.setExtendedState(JFrame.MAXIMIZED_BOTH); } else { ... |
Rectangle | getFramesCurrentScreenSize(JFrame currentFrame) get Frames Current Screen Size Rectangle nonFullScreenBounds = currentFrame.getBounds(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); boolean currentScreenFound = false; int index = 0; java.awt.Rectangle currentScreenSize = null; while (!currentScreenFound && index < gs.length) { java.awt.Rectangle screenBounds = gs[index].getDefaultConfiguration().getBounds(); ... |
Dimension | getFrameSize(Component c) get Frame Size Container parent = getRootContainer(c); if (parent != null) { return parent.getSize(); return Toolkit.getDefaultToolkit().getScreenSize(); |
Dimension | getFrameSize(Component c) get Frame Size Container parent = getRootContainer(c); if (parent != null) { return parent.getSize(); return Toolkit.getDefaultToolkit().getScreenSize(); |
Dimension | getFrameSize(Component c) get Frame Size Container parent = getRootContainer(c); if (parent != null) { return parent.getSize(); return Toolkit.getDefaultToolkit().getScreenSize(); |
boolean | isNormalSizeMode(JFrame window) Check window for normal state. int state = window.getExtendedState(); int mask = Frame.MAXIMIZED_BOTH | Frame.MAXIMIZED_VERT | Frame.MAXIMIZED_HORIZ | Frame.ICONIFIED; return ((state & mask) == 0); |
void | locateWindow(JFrame parent, Dimension mySize, Dimension offset, JDialog me) A helper to position a dialog Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Dimension parSize = parent.getSize(); Point p = parent.getLocation(); int rightX = p.x + parSize.width; if (rightX > screen.width) { rightX = screen.width; int topY = p.y; ... |
void | lockInMinSize(final JFrame frame) lock In Min Size final int origX = frame.getSize().width; final int origY = frame.getSize().height; frame.addComponentListener(new java.awt.event.ComponentAdapter() { @Override public void componentResized(ComponentEvent event) { frame.setSize(Math.max(frame.getWidth(), origX), Math.max(frame.getHeight(), origY)); frame.repaint(); }); |
void | positionFrame(final JFrame frame, final Dimension viewSize, final int addX, final int addY) Set the size and location of the frame. final GraphicsDevice screenDevice = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice(); final DisplayMode displayMode = screenDevice.getDisplayMode(); final Dimension screenSize = new Dimension(displayMode.getWidth(), displayMode.getHeight()); final Dimension frameSize = new Dimension(Math.min(viewSize.width + addX, screenSize.width), Math.min(viewSize.height + addY, screenSize.height)); final int frameX = Math.max((screenSize.width - frameSize.width) / 2, 0); final int frameY = Math.max((screenSize.height - frameSize.height) / 2, 0); ... |
void | resizeApp(JFrame app) resize App if (app != null) {
app.pack();
|