JFrame frame = new JFrame(); Rectangle bounds = getmaximizedBounds(); // set your maximized bounds frame.setMaximizedBounds(bounds); frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
/** * Constructs JFrame and displays it. * */ private void initUI() { frame = new JFrame(Config.config.getProperty("Program.Name") + " - Version " + Config.config.getProperty("Program.Version") + " (build " + DesktopUtils.extractBuildNumber() + ")"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // get screen size Toolkit tk = Toolkit.getDefaultToolkit(); Dimension dim = tk.getScreenSize(); dim.height -= 50; frame.setSize(dim); String s = File.separator; String imgSrc = "config" + s + "themes" + s + "default" + s + "icons" + s + "ondex16" + ".png"; Image icon = null; try { icon = Toolkit.getDefaultToolkit().getImage(imgSrc); } catch (Exception e) { // doesn't matter, it's just an icon } if (icon != null) { frame.setIconImage(icon); } // maximize jframe needs java 1.4 or later GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); frame.setMaximizedBounds(env.getMaximumWindowBounds()); frame.setExtendedState(frame.getExtendedState() | Frame.MAXIMIZED_BOTH); }
private void setFullScreen() { main.setMaximizedBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); main.setExtendedState(main.getExtendedState() | JFrame.MAXIMIZED_BOTH); main.setUndecorated(true); main.setResizable(false); GraphicsDevice device = GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice(); if (device.isFullScreenSupported()) { device.setFullScreenWindow(main); } else { main.setVisible(true); } }
private void setFullScreen() { main.setMaximizedBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); main.setExtendedState(main.getExtendedState() | JFrame.MAXIMIZED_BOTH); main.setUndecorated(true); main.setResizable(false); GraphicsDevice device = GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice(); if (device.isFullScreenSupported()) { device.setFullScreenWindow(main); } else { main.setVisible(true); } }
private void setFullScreen() { main.setMaximizedBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); main.setExtendedState(main.getExtendedState() | JFrame.MAXIMIZED_BOTH); main.setUndecorated(true); main.setResizable(false); GraphicsDevice device = GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice(); if (device.isFullScreenSupported()) { device.setFullScreenWindow(main); } else { main.setVisible(true); } }
/** * Maximize/Restore the window. * * @param maximize iconify {@code true} if we are to maximize the window, * {@code false} if we are to restore the window. */ private void setParentMaximum(boolean maximize) { if (rootParent instanceof JFrame) { JFrame frame = (JFrame) rootParent; int state = frame.getExtendedState(); if (maximize) { GraphicsConfiguration gc = frame.getGraphicsConfiguration(); Insets i = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle r = gc.getBounds(); r.x = 0; r.y = 0; r.width -= i.left + i.right; r.height -= i.top + i.bottom; frame.setMaximizedBounds(r); } frame.setExtendedState(maximize ? state | Frame.MAXIMIZED_BOTH : state & ~Frame.MAXIMIZED_BOTH); } }
/** * Sets maximized bounds according to the display screen insets. */ public void setMaximized() { Component tla = this.root.getTopLevelAncestor(); // fix for defect 213 - maximizing frame under multiple // screens shouldn't always use insets of the primary // screen. GraphicsConfiguration gc = (currentRootPaneGC != null) ? currentRootPaneGC : tla.getGraphicsConfiguration(); Rectangle screenBounds = gc.getBounds(); screenBounds.x = 0; screenBounds.y = 0; Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle maxBounds = new Rectangle( (screenBounds.x + screenInsets.left), (screenBounds.y + screenInsets.top), screenBounds.width - ((screenInsets.left + screenInsets.right)), screenBounds.height - ((screenInsets.top + screenInsets.bottom))); if (tla instanceof JFrame) ((JFrame) tla).setMaximizedBounds(maxBounds); if (MemoryAnalyzer.isRunning()) { MemoryAnalyzer.enqueueUsage("Frame set to bounds " + maxBounds); } }
/** * Sets maximized bounds according to the display screen insets. */ public void setMaximized() { Component tla = this.root.getTopLevelAncestor(); // fix for defect 213 - maximizing frame under multiple // screens shouldn't always use insets of the primary // screen. GraphicsConfiguration gc = (currentRootPaneGC != null) ? currentRootPaneGC : tla.getGraphicsConfiguration(); Rectangle screenBounds = gc.getBounds(); screenBounds.x = 0; screenBounds.y = 0; Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle maxBounds = new Rectangle( (screenBounds.x + screenInsets.left), (screenBounds.y + screenInsets.top), screenBounds.width - ((screenInsets.left + screenInsets.right)), screenBounds.height - ((screenInsets.top + screenInsets.bottom))); if (tla instanceof JFrame) ((JFrame) tla).setMaximizedBounds(maxBounds); if (MemoryAnalyzer.isRunning()) { MemoryAnalyzer.enqueueUsage("Frame set to bounds " + maxBounds); } }