Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Insets scnMax = Toolkit.getDefaultToolkit(). getScreenInsets(dialog.getGraphicsConfiguration()); int taskBarSize = scnMax.bottom; panel.setLayout(new GridBagLayout());
dialog.setBounds(findCenterBounds(parent.getGraphicsConfiguration(), dialog.getSize()));
@Override public void paintIcon(Component c, Graphics g, int x, int y) { if (texture == null) { createTexture(c.getGraphicsConfiguration()); } Graphics2D gr = (Graphics2D) g; gr.setPaint(texture); gr.fillRect(x, y, getIconWidth(), getIconHeight()); super.paintIcon(c, g, x, y); } });
public static void keepComponentInsideScreen(int centerX, int centerY, Component component) { Dimension screenDim = component.getToolkit().getScreenSize(); GraphicsConfiguration g = component.getGraphicsConfiguration(); if (g != null) { Insets insets = component.getToolkit().getScreenInsets(g); // no usable space like toolbar boolean setLocation = false; if (centerX + component.getWidth() > screenDim.width - insets.right) { centerX = (screenDim.width - insets.right) - component.getWidth(); setLocation = true; } else if (centerX < insets.left) { centerX = insets.left; setLocation = true; } if (centerY + component.getHeight() > screenDim.height - insets.bottom) { centerY = (screenDim.height - insets.bottom) - component.getHeight(); setLocation = true; } else if (centerY < insets.top) { centerY = insets.top; setLocation = true; } if (setLocation) { component.setLocation(centerX, centerY); } } else { System.out.println("GuiDisplayUtil::keepComponentInsideScreen -> no GraphicsConfiguration"); } }
getGraphicsConfiguration()); final int taskBarSize = scnMax.bottom;
dialog.setBounds(findCenterBounds(parent.getGraphicsConfiguration(), dialog.getSize()));
public Rectangle getCurrentScreenBounds(Component component) { return component.getGraphicsConfiguration().getBounds(); }
public static Point getLocationOnCurrentScreen(final Component component) { if (component != null) { final Rectangle currentScreenBounds = component.getGraphicsConfiguration().getBounds(); return new Point(currentScreenBounds.x, currentScreenBounds.y); } else { return new Point(0, 0); } }
public static Point getLocationOnCurrentScreen(final Component c) { final Point relativeLocation = c.getLocationOnScreen(); final Rectangle currentScreenBounds = c.getGraphicsConfiguration().getBounds(); relativeLocation.x -= currentScreenBounds.x; relativeLocation.y -= currentScreenBounds.y; return relativeLocation; }
/** * Gets the graphics device (screen) is showing on. * * @param component * the component * @return the graphics device is showing on */ public static GraphicsDevice getGraphicsDeviceIsShowingOn(final Component component) { final GraphicsDevice graphicsDevice = component.getGraphicsConfiguration().getDevice(); return graphicsDevice; }
public static Rectangle getAvailableScreenBounds(Component frame) { final GraphicsConfiguration graphicsConfiguration = frame.getGraphicsConfiguration(); return getScreenBounds(graphicsConfiguration); }
protected void setMaximizeBounds(Frame frame) { // Changed in 1.4.0 to calculate the available screen area each time. Insets screenInsets = Toolkit.getDefaultToolkit(). getScreenInsets(getGraphicsConfiguration()); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // spare any Systemmenus or Taskbars or ??... int w = screenSize.width - screenInsets.left - screenInsets.right; int h = screenSize.height - screenInsets.top - screenInsets.bottom; Rectangle maxBounds = new Rectangle(screenInsets.left, screenInsets.top, w, h); // System.out.println(getTitle() + ".screenSize=" + screenSize + // "\n screenInsets=" + screenInsets + // "\n maxBounds=" + maxBounds); frame.setMaximizedBounds(maxBounds); }
private static GraphicsConfiguration findGraphicsConfiguration(final Component component, int x, int y) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int j = 0; j < gs.length; j++) { GraphicsDevice gd = gs[j]; GraphicsConfiguration[] gc = gd.getConfigurations(); for (int i=0; i < gc.length; i++) { final Rectangle screenBounds = gc[i].getBounds(); if(screenBounds.contains(x, y)) return gc[i]; } } return component != null ? component.getGraphicsConfiguration() : null; }
/** * Get the best graphics configuration for the specified point and component. */ private GraphicsConfiguration graphicsConfigurationForComponent(Component component) { Point point = component.getLocationOnScreen(); // try to find the graphics configuration for our point of interest GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gd = ge.getScreenDevices(); for(int i = 0; i < gd.length; i++) { if(gd[i].getType() != GraphicsDevice.TYPE_RASTER_SCREEN) continue; GraphicsConfiguration defaultGraphicsConfiguration = gd[i].getDefaultConfiguration(); if(!defaultGraphicsConfiguration.getBounds().contains(point)) continue; return defaultGraphicsConfiguration; } // we couldn't find a graphics configuration, use the component's return component.getGraphicsConfiguration(); }
/** * Get the best graphics configuration for the specified point and component. */ private GraphicsConfiguration graphicsConfigurationForComponent(Component component) { Point point = component.getLocationOnScreen(); // try to find the graphics configuration for our point of interest GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gd = ge.getScreenDevices(); for(int i = 0; i < gd.length; i++) { if(gd[i].getType() != GraphicsDevice.TYPE_RASTER_SCREEN) continue; GraphicsConfiguration defaultGraphicsConfiguration = gd[i].getDefaultConfiguration(); if(!defaultGraphicsConfiguration.getBounds().contains(point)) continue; return defaultGraphicsConfiguration; } // we couldn't find a graphics configuration, use the component's return component.getGraphicsConfiguration(); }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { if (texture == null) { createTexture(c.getGraphicsConfiguration()); } Graphics2D gr = (Graphics2D) g; gr.setPaint(texture); gr.fillRect(x, y, getIconWidth(), getIconHeight()); super.paintIcon(c, g, x, y); } });
@Override public final PlatformToplevelWindow createPlatformToplevelWindow(CacioComponent comp) { GraphicsConfiguration gc = comp.getAWTComponent().getGraphicsConfiguration(); PlatformScreen screen = selector.getPlatformScreen(gc); ScreenManagedWindowContainer smwc = screenMap.get(screen); if (smwc == null) { smwc = new ScreenManagedWindowContainer(screen); screenMap.put(screen, smwc); } return new ManagedWindow(smwc, comp); }
/** * Create an off-screen image base on the given component. * * @param component The component to base the off-screen image on. * @param width The width of the image. * @param height The height of the image. * * @return New off-screen image. */ public Image createOffScreenImage(Component component, int width, int height) { GraphicsConfiguration gc = component.getGraphicsConfiguration(); ColorModel model = gc.getColorModel(Transparency.OPAQUE); WritableRaster wr = model.createCompatibleWritableRaster(width, height); return new OffScreenImage(component, model, wr, model.isAlphaPremultiplied()); }
public ImageGraphics2D(OutputStream os, Component component, String format) { super(); this.component = component; init(os, component.getSize(), format); setColor(component.getForeground()); GraphicsConfiguration gc = component.getGraphicsConfiguration(); if (gc != null) setTransform(gc.getDefaultTransform()); }
public ImageGraphics2D(OutputStream os, Component component, String format) { super(); this.component = component; init(os, component.getSize(), format); setColor(component.getForeground()); GraphicsConfiguration gc = component.getGraphicsConfiguration(); if (gc != null) setTransform(gc.getDefaultTransform()); }