java.awt.Window.getGraphicsConfiguration()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中java.awt.Window.getGraphicsConfiguration()方法的一些代码示例,展示了Window.getGraphicsConfiguration()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window.getGraphicsConfiguration()方法的具体详情如下:
包路径:java.awt.Window
类名称:Window
方法名:getGraphicsConfiguration

Window.getGraphicsConfiguration介绍

[英]This method returns the GraphicsConfiguration used by this Window.
[中]此方法返回此窗口使用的图形配置。

代码示例

代码示例来源:origin: chewiebug/GCViewer

public Dimension getPreferredSize() {
  Dimension size = super.getPreferredSize();
  
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(getOwner().getGraphicsConfiguration());
  int taskBarSize = scnMax.bottom;
  
  int usableScreenHeight = screenSize.height - taskBarSize - 50;
  
  if (size.height > (usableScreenHeight)) {
    size.height = usableScreenHeight;
  }
  
  return size;
}

代码示例来源:origin: org.netbeans.api/org-openide-util

/**
 * 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();
}

代码示例来源:origin: org.netbeans.api/org-openide-util-ui

/**
 * 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();
}

代码示例来源:origin: stackoverflow.com

w.setBounds(w.getGraphicsConfiguration().getBounds());
w.setVisible(true);

代码示例来源:origin: stackoverflow.com

Window w=new Window(null)
{
 @Override
 public void paint(Graphics g)
 {
  final Font font = getFont().deriveFont(48f);
  g.setFont(font);
  g.setColor(Color.RED);
  final String message = "Hello";
  FontMetrics metrics = g.getFontMetrics();
  g.drawString(message,
   (getWidth()-metrics.stringWidth(message))/2,
   (getHeight()-metrics.getHeight())/2);
 }
 @Override
 public void update(Graphics g)
 {
  paint(g);
 }
};
w.setAlwaysOnTop(true);
w.setBounds(w.getGraphicsConfiguration().getBounds());
w.setBackground(new Color(0, true));
w.setVisible(true);

代码示例来源:origin: stackoverflow.com

public GraphicsDevice getMonitorWindowIsOn(Window window)
{
  // First, grab the x,y position of the Window object
  GraphicsConfiguration windowGraphicsConfig = window.getGraphicsConfiguration();
  if (windowGraphicsConfig == null)
  {
     return null; // Should probably be handled better
  }
  Rectangle windowBounds = windowGraphicsConfig.getBounds();

  for (GraphicsDevice gd : ge.getScreenDevices()) {
    Rectangle monitorBounds = gd.getDefaultConfiguration().getBounds();
    if (monitorBounds.contains(windowBounds.x, windowBounds.y))
    {
      return gd;
    }
  }
  // um, return null I guess, should make this default better though,
  // maybe to the default screen device, except, I am sure if no monitors are
  // connected that may be null as well.
  return null;
}

代码示例来源:origin: com.github.lgooddatepicker/LGoodDatePicker

/**
 * 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;
}

代码示例来源:origin: mucommander/mucommander

/**
 * Computes the screen's insets for the specified window and returns them.
 * <p>
 * While this might seem strange, screen insets can change from one window
 * to another. For example, on X11 windowing systems, there is no guarantee that
 * a window will be displayed on the same screen, let alone computer, as the one
 * the application is running on.
 * </p>
 * @param window the window for which screen insets should be computed.
 * @return the screen's insets for the specified window
 */
public static Insets getScreenInsets(Window window) {
  return Toolkit.getDefaultToolkit().getScreenInsets(window.getGraphicsConfiguration());
}

代码示例来源:origin: mucommander/mucommander

/**
 * Computes the screen's insets for the specified window and returns them.
 * <p>
 * While this might seem strange, screen insets can change from one window
 * to another. For example, on X11 windowing systems, there is no guarantee that
 * a window will be displayed on the same screen, let alone computer, as the one
 * the application is running on.
 * </p>
 * @param window the window for which screen insets should be computed.
 * @return the screen's insets for the specified window
 */
public static Insets getScreenInsets(Window window) {
  return Toolkit.getDefaultToolkit().getScreenInsets(window.getGraphicsConfiguration());
}

代码示例来源:origin: mucommander/mucommander

/**
   * Returns the maximum dimensions for a full-screen window.
   *
   * @param window window who's full screen size should be computed.
   * @return the maximum dimensions for a full-screen window
   */
  public static Rectangle getFullScreenBounds(Window window) {
    Toolkit   toolkit;
    Dimension screenSize;

    toolkit    = Toolkit.getDefaultToolkit();
    screenSize = toolkit.getScreenSize();

    Insets screenInsets = toolkit.getScreenInsets(window.getGraphicsConfiguration());
    return new Rectangle(screenInsets.left, screenInsets.top, screenSize.width-screenInsets.left-screenInsets.right, screenSize.height-screenInsets.top-screenInsets.bottom);
  }
}

代码示例来源:origin: org.jdesktop.bsaf/bsaf

/**
 * Calculates default location for the specified window.
 * @return default location for the window
 * @param window the window location is calculated for.
 *               It should not be null.
 */
public static Point defaultLocation(Window window) {
  GraphicsConfiguration gc = window.getGraphicsConfiguration();
  Rectangle bounds = gc.getBounds();
  Insets insets = window.getToolkit().getScreenInsets(gc);
  int x = bounds.x + insets.left;
  int y = bounds.y + insets.top;
  return new Point(x, y);
}

代码示例来源:origin: stackoverflow.com

static public Insets getScreenInsets(Window wnd) {
 Insets                              si;
 try {
   if(wnd==null) { si=Toolkit.getDefaultToolkit().getScreenInsets(new Frame().getGraphicsConfiguration()); }
   else          { si=wnd.getToolkit()           .getScreenInsets(wnd.getGraphicsConfiguration());         }
   } catch(NoSuchMethodError thr) { si=new Insets(0,0,0,0); }
 return si;
 }

代码示例来源:origin: org.bitbucket.goalhub.simpleide/jedit

private static Point fitInScreen(Point p, Window w, int lineHeight)
{
  Rectangle screenSize = w.getGraphicsConfiguration().getBounds();
  if(p.y + w.getHeight() >= screenSize.height)
    p.y = p.y - w.getHeight() - lineHeight;
  return p;
} //}}}

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

private static Rectangle getUsableDeviceBounds(Window window) {
  Window owner = window.getOwner();
  GraphicsConfiguration gc = null;
  
  if (owner == null) {
    gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
        .getDefaultScreenDevice().getDefaultConfiguration();
  } else {
    gc = owner.getGraphicsConfiguration();
  }
  
  Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
  Rectangle 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;
}

代码示例来源:origin: in.jlibs/org-openide-util

/**
 * 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();
}

代码示例来源:origin: org.bitbucket.goalhub.simpleide/jedit

private static Point fitInScreen(Point p, Window w, int lineHeight)
{
  Rectangle screenSize = w.getGraphicsConfiguration().getBounds();
  if(p.y + w.getHeight() >= screenSize.height)
    p.y = p.y - w.getHeight() - lineHeight;
  return p;
} //}}}

代码示例来源:origin: org.gosu-lang.gosu/gosu-editor

public static void ensureWindowIsVisible( Window w )
{
 int width = w.getWidth();
 int height = w.getHeight();
 Toolkit toolkit = Toolkit.getDefaultToolkit();
 GraphicsConfiguration gc = w.getGraphicsConfiguration();
 Insets screenInsets = toolkit.getScreenInsets( gc );
 Rectangle screenSize = gc.getBounds();
 w.setLocation( Math.max( screenInsets.left, Math.min( w.getX(), screenSize.width - screenInsets.right - width ) ),
         Math.max( screenInsets.top, Math.min( w.getY(), screenSize.height - screenInsets.bottom - height ) ) );
}

代码示例来源:origin: net.sourceforge.mydoggy/mydoggy-plaf

public static void restoreFullScreenWindow(Window window) {
  Rectangle bounds = fullScreenBounds.remove(window);
  if (bounds != null) {
    window.setBounds(bounds);
  } else {
    GraphicsDevice graphicsDevice = window.getGraphicsConfiguration().getDevice();
    if (graphicsDevice.isFullScreenSupported())
      graphicsDevice.setFullScreenWindow(null);
  }
}

代码示例来源:origin: otros-systems/otroslogviewer

public static void centerOnScreen(Window target) {
 DisplayMode displayMode = target.getGraphicsConfiguration().getDevice().getDisplayMode();
 int displayHeight = displayMode.getHeight();
 int displayWidth = displayMode.getWidth();
 Dimension targetSize = target.getSize();
 Point frameLocation = new Point(displayWidth / 2 - targetSize.width / 2, displayHeight / 2 - targetSize.height / 2);
 target.setLocation(frameLocation);
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-swing-core

public static void centerToScreen(final Window window) {
 if (window == null) {
  return;
 }
 final DisplayMode displayMode = window.getGraphicsConfiguration().getDevice().getDisplayMode();
 final Point location = getCenterToScreenLocation(displayMode, window.getSize());
 window.setLocation(location);
 return;
}

相关文章

Window类方法