Java Code Examples for java.awt.GraphicsEnvironment#getMaximumWindowBounds()
The following examples show how to use
java.awt.GraphicsEnvironment#getMaximumWindowBounds() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JIntellitypeDemo.java From jintellitype with Apache License 2.0 | 6 votes |
/** * Centers window on desktop. * <p> * * @param aFrame the Frame to center */ private static void center(JFrame aFrame) { final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final Point centerPoint = ge.getCenterPoint(); final Rectangle bounds = ge.getMaximumWindowBounds(); final int w = Math.min(aFrame.getWidth(), bounds.width); final int h = Math.min(aFrame.getHeight(), bounds.height); final int x = centerPoint.x - (w / 2); final int y = centerPoint.y - (h / 2); aFrame.setBounds(x, y, w, h); if ((w == bounds.width) && (h == bounds.height)) { aFrame.setExtendedState(Frame.MAXIMIZED_BOTH); } aFrame.validate(); }
Example 2
Source File: ScreenSizeChangeTest.java From haxademic with MIT License | 6 votes |
protected void firstFrame() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); screenSize = ge.getMaximumWindowBounds(); Toolkit toolkit = Toolkit.getDefaultToolkit(); toolkit.addAWTEventListener(new AWTEventListener() { @Override public void eventDispatched(AWTEvent event) { // take a look at http://stackoverflow.com/questions/10123735/get-effective-screen-size-from-java Rectangle newSize = ge.getMaximumWindowBounds(); if (newSize.width != screenSize.width || newSize.height != screenSize.height) { screenSize.setSize(newSize.width, newSize.height); resize(); } } }, AWTEvent.PAINT_EVENT_MASK); }
Example 3
Source File: InternalFrameDemoFrame.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
/** * Computes the maximum bounds of the current screen device. If this method is called on JDK 1.4, Xinerama-aware * results are returned. (See Sun-Bug-ID 4463949 for details). * * @return the maximum bounds of the current screen. */ private static Rectangle getMaximumWindowBounds() { try { final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); return localGraphicsEnvironment.getMaximumWindowBounds(); } catch (Exception e) { // ignore ... will fail if this is not a JDK 1.4 .. } final Dimension s = Toolkit.getDefaultToolkit().getScreenSize(); return new Rectangle(0, 0, s.width, s.height); }
Example 4
Source File: WindowUtils.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Determines the screen that most contains the specified global bounds and returns the maximum * size a window can be on that screen. * * @param bounds The global bounds to use when determining the maximum bounds for a window. * @return The maximum bounds that fits on a screen. */ public static Rectangle getMaximumWindowBounds(Rectangle bounds) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = getPreferredScreenDevice(bounds); if (gd == ge.getDefaultScreenDevice()) { bounds = ge.getMaximumWindowBounds(); // The Mac (and now Windows as of Java 5) already return the correct // value... try to fix it up for the other platforms. This doesn't // currently work, either, since the other platforms seem to always // return empty insets. if (!Platform.isMacintosh() && !Platform.isWindows()) { Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gd.getDefaultConfiguration()); // Since this is failing to do the right thing anyway, we're going // to try and come up with some reasonable limitations... if (insets.top == 0 && insets.bottom == 0) { insets.bottom = 48; } bounds.x += insets.left; bounds.y += insets.top; bounds.width -= insets.left + insets.right; bounds.height -= insets.top + insets.bottom; } return bounds; } return gd.getDefaultConfiguration().getBounds(); }
Example 5
Source File: CropImageDialog.java From swingsane with Apache License 2.0 | 5 votes |
private void setMaximumWindowBounds() { GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); maximumWindowSize = graphicsEnvironment.getMaximumWindowBounds(); maximumWindowSize.height -= 50; this.setBounds(maximumWindowSize); Dimension bounds = maximumWindowSize.getSize(); setPreferredSize(bounds); setSize(bounds); }
Example 6
Source File: TelegraphConfig.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Gets the screen resolution. * * @return The screen resolution. */ private Rectangle getScreenResolution() { // get the environment final GraphicsEnvironment environment = GraphicsEnvironment .getLocalGraphicsEnvironment(); // return the bounds return environment.getMaximumWindowBounds(); }
Example 7
Source File: ComponentMover.java From mars-sim with GNU General Public License v3.0 | 5 votes |
private Dimension getBoundingSize(Component source) { if (source instanceof Window) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = env.getMaximumWindowBounds(); return new Dimension(bounds.width, bounds.height); } else { return source.getParent().getSize(); } }
Example 8
Source File: SwingUtil.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Computes the maximum bounds of the current screen device. If this method is called on JDK 1.4, Xinerama-aware * results are returned. (See Sun-Bug-ID 4463949 for details). * * @return the maximum bounds of the current screen. */ public static Rectangle getMaximumWindowBounds() { try { final GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); return localGraphicsEnvironment.getMaximumWindowBounds(); } catch ( Exception e ) { // ignore ... will fail if this is not a JDK 1.4 .. } final Dimension s = Toolkit.getDefaultToolkit().getScreenSize(); return new Rectangle( 0, 0, s.width, s.height ); }
Example 9
Source File: Toaster.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 4 votes |
@Override public void run() { try { boolean animateFromBottom = true; GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); Rectangle screenRect = ge.getMaximumWindowBounds(); int screenHeight = (int) screenRect.height; int startYPosition; int stopYPosition; if (screenRect.y > 0) { animateFromBottom = false; // Animate from top! } maxToasterInSceen = screenHeight / toasterHeight; int posx = (int) screenRect.width - toasterWidth - 1; toaster.setLocation(posx, screenHeight); toaster.setVisible(true); if (useAlwaysOnTop) { toaster.setAlwaysOnTop(true); } if (animateFromBottom) { startYPosition = screenHeight; stopYPosition = startYPosition - toasterHeight - 1; if (currentNumberOfToaster > 0) { stopYPosition = stopYPosition - (maxToaster % maxToasterInSceen * toasterHeight); } else { maxToaster = 0; } } else { startYPosition = screenRect.y - toasterHeight; stopYPosition = screenRect.y; if (currentNumberOfToaster > 0) { stopYPosition = stopYPosition + (maxToaster % maxToasterInSceen * toasterHeight); } else { maxToaster = 0; } } currentNumberOfToaster++; maxToaster++; animateVertically(posx, startYPosition, stopYPosition); Thread.sleep(displayTime); animateVertically(posx, stopYPosition, startYPosition); currentNumberOfToaster--; toaster.setVisible(false); toaster.dispose(); } catch (Exception e) { Logger.getLogger(Toaster.class.getName()).log(Level.SEVERE, null, e); } }
Example 10
Source File: Toaster.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 4 votes |
@Override public void run() { try { boolean animateFromBottom = true; GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); Rectangle screenRect = ge.getMaximumWindowBounds(); int screenHeight = (int) screenRect.height; int startYPosition; int stopYPosition; if (screenRect.y > 0) { animateFromBottom = false; // Animate from top! } maxToasterInSceen = screenHeight / toasterHeight; int posx = (int) screenRect.width - toasterWidth - 1; toaster.setLocation(posx, screenHeight); toaster.setVisible(true); if (useAlwaysOnTop) { toaster.setAlwaysOnTop(true); } if (animateFromBottom) { startYPosition = screenHeight; stopYPosition = startYPosition - toasterHeight - 1; if (currentNumberOfToaster > 0) { stopYPosition = stopYPosition - (maxToaster % maxToasterInSceen * toasterHeight); } else { maxToaster = 0; } } else { startYPosition = screenRect.y - toasterHeight; stopYPosition = screenRect.y; if (currentNumberOfToaster > 0) { stopYPosition = stopYPosition + (maxToaster % maxToasterInSceen * toasterHeight); } else { maxToaster = 0; } } currentNumberOfToaster++; maxToaster++; animateVertically(posx, startYPosition, stopYPosition); Thread.sleep(displayTime); animateVertically(posx, stopYPosition, startYPosition); currentNumberOfToaster--; toaster.setVisible(false); toaster.dispose(); } catch (Exception e) { } }