Java Code Examples for java.awt.Window#getGraphicsConfiguration()
The following examples show how to use
java.awt.Window#getGraphicsConfiguration() .
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: Utilities.java From netbeans with Apache License 2.0 | 6 votes |
/** * Finds out the monitor where the user currently has the input focus. * This method is usually used to help the client code to figure out on * which monitor it should place newly created windows/frames/dialogs. * * @return the GraphicsConfiguration of the monitor which currently has the * input focus */ private static GraphicsConfiguration getCurrentGraphicsConfiguration() { Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (focusOwner != null) { Window w = SwingUtilities.getWindowAncestor(focusOwner); if (w != null) { return w.getGraphicsConfiguration(); } else { //#217737 - try to find the main window which could be placed in secondary screen for( Frame f : Frame.getFrames() ) { if( "NbMainWindow".equals(f.getName())) { //NOI18N return f.getGraphicsConfiguration(); } } } } return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); }
Example 2
Source File: InternalUtilities.java From LGoodDatePicker with MIT License | 6 votes |
/** * getScreenWorkingArea, This returns the working area of the screen. (The working area excludes * any task bars.) This function accounts for multi-monitor setups. If a window is supplied, * then the the monitor that contains the window will be used. If a window is not supplied, then * the primary monitor will be used. */ static public Rectangle getScreenWorkingArea(Window windowOrNull) { Insets insets; Rectangle bounds; if (windowOrNull == null) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); insets = Toolkit.getDefaultToolkit().getScreenInsets(ge.getDefaultScreenDevice() .getDefaultConfiguration()); bounds = ge.getDefaultScreenDevice().getDefaultConfiguration().getBounds(); } else { GraphicsConfiguration gc = windowOrNull.getGraphicsConfiguration(); insets = windowOrNull.getToolkit().getScreenInsets(gc); bounds = gc.getBounds(); } bounds.x += insets.left; bounds.y += insets.top; bounds.width -= (insets.left + insets.right); bounds.height -= (insets.top + insets.bottom); return bounds; }
Example 3
Source File: LGuiUtils.java From scelight with Apache License 2.0 | 6 votes |
/** * 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. * * <p> * The implementation takes the screen insets (for example space occupied by task bar) into account. * </p> * * @param window window to be resized * @param margin margin to leave around the window * @param maxSize optional parameter defining a maximum size */ public static void maximizeWindowWithMargin( final Window window, final int margin, final Dimension maxSize ) { // Maybe use window.getGraphicsConfiguration() (it probably accounts multi-screens!) // Edit: it does, but setLocationRelativeTo() at the end will always use the default screen device! 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 ) window.setSize( width, height ); else window.setSize( Math.min( width, maxSize.width ), Math.min( height, maxSize.height ) ); // And finally center on screen // window.setLocationRelativeTo( null ) always centers on the main screen, so: window.setLocationRelativeTo( window.getOwner() ); }
Example 4
Source File: TreeLockDeadlock.java From hottub with GNU General Public License v2.0 | 5 votes |
private static void test(final Window window) throws Exception { final long start = System.nanoTime(); final long end = start + NANOSECONDS.convert(1, MINUTES); final Runnable r1 = () -> { while (System.nanoTime() < end) { window.setBounds(window.getBounds()); } }; final Runnable r2 = () -> { while (System.nanoTime() < end) { window.getGraphicsConfiguration(); window.getOpacity(); } }; final Thread t1 = new Thread(r1); final Thread t2 = new Thread(r1); final Thread t3 = new Thread(r2); final Thread t4 = new Thread(r2); t1.start(); t2.start(); t3.start(); t4.start(); t1.join(); t2.join(); t3.join(); t4.join(); }
Example 5
Source File: Platform.java From DroidUIBuilder with Apache License 2.0 | 5 votes |
/** * Finds out the monitor where the user currently has the input focus. * This method is usually used to help the client code to figure out on * which monitor it should place newly created windows/frames/dialogs. * * @return the GraphicsConfiguration of the monitor which currently has the * input focus */ private static GraphicsConfiguration getCurrentGraphicsConfiguration() { Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (focusOwner != null) { Window w = SwingUtilities.getWindowAncestor(focusOwner); if (w != null) { return w.getGraphicsConfiguration(); } } return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); }
Example 6
Source File: Platform.java From beautyeye with Apache License 2.0 | 5 votes |
/** * Finds out the monitor where the user currently has the input focus. * This method is usually used to help the client code to figure out on * which monitor it should place newly created windows/frames/dialogs. * * @return the GraphicsConfiguration of the monitor which currently has the * input focus */ private static GraphicsConfiguration getCurrentGraphicsConfiguration() { Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (focusOwner != null) { Window w = SwingUtilities.getWindowAncestor(focusOwner); if (w != null) { return w.getGraphicsConfiguration(); } } return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); }
Example 7
Source File: Util.java From triplea with GNU General Public License v3.0 | 5 votes |
/** Returns the size of the screen associated with the passed window. */ public static Dimension getScreenSize(final Window window) { final var graphicsConfiguration = window.getGraphicsConfiguration(); if (graphicsConfiguration == null) { return Toolkit.getDefaultToolkit().getScreenSize(); } final var displayMode = graphicsConfiguration.getDevice().getDisplayMode(); return new Dimension(displayMode.getWidth(), displayMode.getHeight()); }
Example 8
Source File: InternalUtilities.java From LGoodDatePicker with MIT License | 5 votes |
/** * getScreenTotalArea, This returns the total area of the screen. (The total area includes any * task bars.) This function accounts for multi-monitor setups. If a window is supplied, then * the the monitor that contains the window will be used. If a window is not supplied, then the * primary monitor will be used. */ static public Rectangle getScreenTotalArea(Window windowOrNull) { Rectangle bounds; if (windowOrNull == null) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); bounds = ge.getDefaultScreenDevice().getDefaultConfiguration().getBounds(); } else { GraphicsConfiguration gc = windowOrNull.getGraphicsConfiguration(); bounds = gc.getBounds(); } return bounds; }
Example 9
Source File: TreeLockDeadlock.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static void test(final Window window) throws Exception { final long start = System.nanoTime(); final long end = start + NANOSECONDS.convert(1, MINUTES); final Runnable r1 = () -> { while (System.nanoTime() < end) { window.setBounds(window.getBounds()); } }; final Runnable r2 = () -> { while (System.nanoTime() < end) { window.getGraphicsConfiguration(); window.getOpacity(); } }; final Thread t1 = new Thread(r1); final Thread t2 = new Thread(r1); final Thread t3 = new Thread(r2); final Thread t4 = new Thread(r2); t1.start(); t2.start(); t3.start(); t4.start(); t1.join(); t2.join(); t3.join(); t4.join(); }
Example 10
Source File: TreeLockDeadlock.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static void test(final Window window) throws Exception { final long start = System.nanoTime(); final long end = start + NANOSECONDS.convert(1, MINUTES); final Runnable r1 = () -> { while (System.nanoTime() < end) { window.setBounds(window.getBounds()); } }; final Runnable r2 = () -> { while (System.nanoTime() < end) { window.getGraphicsConfiguration(); window.getOpacity(); } }; final Thread t1 = new Thread(r1); final Thread t2 = new Thread(r1); final Thread t3 = new Thread(r2); final Thread t4 = new Thread(r2); t1.start(); t2.start(); t3.start(); t4.start(); t1.join(); t2.join(); t3.join(); t4.join(); }
Example 11
Source File: TreeLockDeadlock.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static void test(final Window window) throws Exception { final long start = System.nanoTime(); final long end = start + NANOSECONDS.convert(1, MINUTES); final Runnable r1 = () -> { while (System.nanoTime() < end) { window.setBounds(window.getBounds()); } }; final Runnable r2 = () -> { while (System.nanoTime() < end) { window.getGraphicsConfiguration(); window.getOpacity(); } }; final Thread t1 = new Thread(r1); final Thread t2 = new Thread(r1); final Thread t3 = new Thread(r2); final Thread t4 = new Thread(r2); t1.start(); t2.start(); t3.start(); t4.start(); t1.join(); t2.join(); t3.join(); t4.join(); }
Example 12
Source File: TreeLockDeadlock.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void test(final Window window) throws Exception { final long start = System.nanoTime(); final long end = start + NANOSECONDS.convert(1, MINUTES); final Runnable r1 = () -> { while (System.nanoTime() < end) { window.setBounds(window.getBounds()); } }; final Runnable r2 = () -> { while (System.nanoTime() < end) { window.getGraphicsConfiguration(); window.getOpacity(); } }; final Thread t1 = new Thread(r1); final Thread t2 = new Thread(r1); final Thread t3 = new Thread(r2); final Thread t4 = new Thread(r2); t1.start(); t2.start(); t3.start(); t4.start(); t1.join(); t2.join(); t3.join(); t4.join(); }
Example 13
Source File: TreeLockDeadlock.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static void test(final Window window) throws Exception { final long start = System.nanoTime(); final long end = start + NANOSECONDS.convert(1, MINUTES); final Runnable r1 = () -> { while (System.nanoTime() < end) { window.setBounds(window.getBounds()); } }; final Runnable r2 = () -> { while (System.nanoTime() < end) { window.getGraphicsConfiguration(); window.getOpacity(); } }; final Thread t1 = new Thread(r1); final Thread t2 = new Thread(r1); final Thread t3 = new Thread(r2); final Thread t4 = new Thread(r2); t1.start(); t2.start(); t3.start(); t4.start(); t1.join(); t2.join(); t3.join(); t4.join(); }
Example 14
Source File: NoNativeAccessWindowSystem.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void setWindowMask(Window w, Shape mask) { GraphicsConfiguration gc = w.getGraphicsConfiguration(); GraphicsDevice gd = gc.getDevice(); if (gc.getDevice().getFullScreenWindow() == w) { return; } if (!gd.isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT)) { return; } w.setShape(mask); }
Example 15
Source File: NoNativeAccessWindowSystem.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void setWindowAlpha(Window w, float alpha) { GraphicsConfiguration gc = w.getGraphicsConfiguration(); GraphicsDevice gd = gc.getDevice(); if (gc.getDevice().getFullScreenWindow() == w) { return; } if (!gd.isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT)) { return; } w.setOpacity(alpha); }
Example 16
Source File: ColumnSelectionPanel.java From netbeans with Apache License 2.0 | 5 votes |
private static GraphicsConfiguration getCurrentGraphicsConfiguration() { Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (focusOwner != null) { Window w = SwingUtilities.getWindowAncestor(focusOwner); if (w != null) { return w.getGraphicsConfiguration(); } } return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); }
Example 17
Source File: TreeLockDeadlock.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void test(final Window window) throws Exception { final long start = System.nanoTime(); final long end = start + NANOSECONDS.convert(1, MINUTES); final Runnable r1 = () -> { while (System.nanoTime() < end) { window.setBounds(window.getBounds()); } }; final Runnable r2 = () -> { while (System.nanoTime() < end) { window.getGraphicsConfiguration(); window.getOpacity(); } }; final Thread t1 = new Thread(r1); final Thread t2 = new Thread(r1); final Thread t3 = new Thread(r2); final Thread t4 = new Thread(r2); t1.start(); t2.start(); t3.start(); t4.start(); t1.join(); t2.join(); t3.join(); t4.join(); }
Example 18
Source File: TreeLockDeadlock.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void test(final Window window) throws Exception { final long start = System.nanoTime(); final long end = start + NANOSECONDS.convert(1, MINUTES); final Runnable r1 = () -> { while (System.nanoTime() < end) { window.setBounds(window.getBounds()); } }; final Runnable r2 = () -> { while (System.nanoTime() < end) { window.getGraphicsConfiguration(); window.getOpacity(); } }; final Thread t1 = new Thread(r1); final Thread t2 = new Thread(r1); final Thread t3 = new Thread(r2); final Thread t4 = new Thread(r2); t1.start(); t2.start(); t3.start(); t4.start(); t1.join(); t2.join(); t3.join(); t4.join(); }
Example 19
Source File: PopupAction.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
private Point calculatePosition(Component source) { if (!source.isShowing()) { // should not happen, but better safe than sorry return new Point(0, 0); } int xSource = source.getLocationOnScreen().x; int ySource = source.getLocationOnScreen().y; // get size of popup Dimension popupSize = popupComponent.getSize(); if (popupSize.width == 0) { popupSize = ((Component) popupComponent).getPreferredSize(); } int xPopup = 0; int yPopup = 0; // get max x and y screen coordinates Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); if (focusedWindow == null) { // should not happen, but better safe than sorry return new Point(xSource, ySource); } GraphicsConfiguration graphicsConfig = focusedWindow.getGraphicsConfiguration(); if (graphicsConfig == null) { // should not happen, but better safe than sorry return new Point(xSource, ySource); } Rectangle bounds = graphicsConfig.getBounds(); Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfig); int maxScreenX = (int) (bounds.getX() + bounds.getWidth() - screenInsets.right); int maxScreenY = (int) (bounds.getY() + bounds.getHeight() - screenInsets.bottom); switch (position) { case VERTICAL: // place popup at sources' x position xPopup = xSource; // place popup always below source (to avoid overlapping) yPopup = ySource + source.getHeight(); // check if popup is outside active window if (xPopup + popupSize.width > maxScreenX) { // move popup x position to the left // to fit inside the active window xPopup = maxScreenX - popupSize.width - BORDER_OFFSET; } // if the popup now would be moved outside of screen to the left it would look // silly, so in that case just show it at its intended position and let it be cut // off on the right side as we cannot do anything about it if (xPopup < bounds.getX() + screenInsets.left) { xPopup = (int) (bounds.getX() + screenInsets.left); } break; case HORIZONTAL: // place popup always to the right side of the source (to avoid overlapping) xPopup = xSource + source.getWidth(); // place popup at sources' y position yPopup = ySource; // check if popup is outside active window if (yPopup + popupSize.height > maxScreenY) { // move popup upwards to fit into active window yPopup = maxScreenY - popupSize.height - BORDER_OFFSET; } // if the popup now would be moved outside of screen at the top it would look // silly, so in that case just show it at top of screen and let it be cut // off on the bottom side as we cannot do anything about it if (yPopup < bounds.getY() + screenInsets.top) { yPopup = (int) (bounds.getY() + screenInsets.top); } break; } return new Point(xPopup, yPopup); }
Example 20
Source File: ButtonDialog.java From rapidminer-studio with GNU Affero General Public License v3.0 | 2 votes |
/** * Constructor used by the {@link ButtonDialogBuilder} and can also be used when subclassing. * * @param owner * the owner or {@code null}. Note that an owner should be set if the dialog will be * modal, otherwise the order ends up being undefined and causing all sorts of * trouble * @param key * the i18n key * @param modalityType * the modality type * @param arguments * the optional i18n arguments * @since 6.5.0 */ protected ButtonDialog(Window owner, String key, ModalityType modalityType, Object... arguments) { this(owner, key, modalityType, owner != null ? owner.getGraphicsConfiguration() : null, arguments); }