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

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

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

Window.getWidth介绍

暂无

代码示例

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

public static void centreWindow(Window frame) {
  Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
  int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2);
  int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2);
  frame.setLocation(x, y);
}

代码示例来源:origin: skylot/jadx

public void saveWindowPos(Window window) {
  WindowLocation pos = new WindowLocation(window.getClass().getSimpleName(),
      window.getX(), window.getY(),
      window.getWidth(), window.getHeight()
  );
  windowPos.put(pos.getWindowId(), pos);
  partialSync(settings -> settings.windowPos = windowPos);
}

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

public void setVisible(boolean visible) {
  if (visible) {
    int x = (int) getOwner().getLocation().getX() + (getOwner().getWidth() / 2) - (getWidth() / 2);
    int y = (int) getOwner().getLocation().getY() + (getOwner().getHeight() / 2) - (getHeight() / 2);
    setLocation(adjustX(x), adjustY(y));
  }
  
  super.setVisible(visible);
}

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

public static void centerOnScreen(Window w, Window parent) {
  Rectangle r = new Rectangle();
  if (parent == null) {
    r.setSize(Toolkit.getDefaultToolkit().getScreenSize());
  } else {
    r.setLocation(parent.getLocation());
    r.setSize(parent.getSize());
  }
  // Determine the new location of the alert
  int x = r.x + (r.width - w.getWidth()) / 2;
  int y = r.y + (r.height - w.getHeight()) / 2;
  // Move the alert
  w.setLocation(x, y);
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Updates the font metrics the first time we're displayed.
 */
@Override
public void addNotify() {
  super.addNotify();
  // Some LookAndFeels (e.g. WebLaF) for some reason have a 0x0 parent
  // window initially (perhaps something to do with them fading in?),
  // which will cause an exception from getGraphics(), so we must be
  // careful here.
  if (metricsNeverRefreshed) {
    Window parent = SwingUtilities.getWindowAncestor(this);
    if (parent!=null && parent.getWidth()>0 && parent.getHeight()>0) {
      refreshFontMetrics(getGraphics2D(getGraphics()));
      metricsNeverRefreshed = false;
    }
  }
  // Re-start parsing if we were removed from one container and added
  // to another
  if (parserManager!=null) {
    parserManager.restartParsing();
  }
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

@Override
public void mouseDragged(MouseEvent e) {
  Point newPos = e.getPoint();
  SwingUtilities.convertPointToScreen(newPos, SizeGrip.this);
  int xDelta = newPos.x - origPos.x;
  int yDelta = newPos.y - origPos.y;
  Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this);
  if (wind!=null) { // Should always be true
    if (getComponentOrientation().isLeftToRight()) {
      int w = wind.getWidth();
      if (newPos.x>=wind.getX()) {
        w += xDelta;
      }
      int h = wind.getHeight();
      if (newPos.y>=wind.getY()) {
        h += yDelta;
      }
      wind.setSize(w,h);
    }
    else { // RTL
      int newW = Math.max(1, wind.getWidth()-xDelta);
      int newH = Math.max(1, wind.getHeight()+yDelta);
      wind.setBounds(newPos.x, wind.getY(), newW, newH);
    }
    // invalidate()/validate() needed pre-1.6.
    wind.invalidate();
    wind.validate();
  }
  origPos.setLocation(newPos);
}

代码示例来源:origin: apache/pdfbox

@Override
  public void mouseClicked(MouseEvent e)
  {
    Window viewer = LogDialog.instance().getOwner();
    
    // show the log window
    LogDialog.instance().setSize(800, 400);
    LogDialog.instance().setVisible(true);
    LogDialog.instance().setLocation(viewer.getLocationOnScreen().x + viewer.getWidth() / 2,
                     viewer.getLocationOnScreen().y + viewer.getHeight() / 2);
  }
});

代码示例来源:origin: org.apache.cayenne.modeler/cayenne-modeler

@Override
  public void componentResized(ComponentEvent e) {
    setWidth(window.getWidth());
    setHeight(window.getHeight());
  }
});

代码示例来源:origin: h3xstream/http-script-generator

private void centerWindow(Window frame) {
  Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
  int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2);
  int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2);
  frame.setLocation(x, y);
}

代码示例来源:origin: jdfekete/geneaquilt

/**
 * Centers a window on the primary display
 */
public static void centerOnPrimaryScreen(Window toplevel) {
  Dimension screenRes = Toolkit.getDefaultToolkit().getScreenSize();
  toplevel.setLocation((screenRes.width - toplevel.getWidth()) / 2,
      (screenRes.height - toplevel.getHeight()) / 2);
}

代码示例来源:origin: xyz.cofe/gui.swing

@Override
  public void recive(Window wnd) {
    if( wnd==null )return;
    int cw = wnd.getWidth();
    int ch = wnd.getHeight();
    if( cw<w || ch<h ){
      int tw = Math.max(cw, w);
      int th = Math.max(ch, h);
      wnd.setSize(tw, th);
    }
  }
};

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

public static void centreWindow(Window frame) {
  Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
  int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2);
  int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2);
  frame.setLocation(x, y);
}

代码示例来源:origin: org.jspresso/jspresso-swing-components

/**
 * Center a window on screen.
 * 
 * @param w
 *            the window to center on screen.
 */
public static void centerOnScreen(Window w) {
 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
 w.setLocation((screenDim.width - w.getWidth()) / 2, (screenDim.height - w
   .getHeight()) / 2);
}

代码示例来源:origin: org.jspresso.framework/jspresso-swing-components

/**
 * Center a window on screen.
 *
 * @param w
 *          the window to center on screen.
 */
public static void centerOnScreen(Window w) {
 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
 w.setLocation((screenDim.width - w.getWidth()) / 2,
   (screenDim.height - w.getHeight()) / 2);
}

代码示例来源:origin: nroduit/Weasis

public static void showCenterScreen(Window window) {
  try {
    Rectangle bound = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
      .getDefaultConfiguration().getBounds();
    window.setLocation(bound.x + (bound.width - window.getWidth()) / 2,
      bound.y + (bound.height - window.getHeight()) / 2);
  } catch (Exception e) {
    LOGGER.error("Cannot center the window to the screen", e); //$NON-NLS-1$
  }
  window.setVisible(true);
}

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

/** We can't get any motion events on an empty frame. */
  private boolean isEmptyFrame(Window w) {
    Insets insets = AWT.getInsets(w);
    return insets.top + insets.bottom == w.getHeight()
      || insets.left + insets.right == w.getWidth();
  }
}

代码示例来源: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: robo-code/robocode

/**
 * Packs, centers, and shows the specified window on the screen.
 * @param window the window to pack, center, and show
 * @param center {@code true} if the window must be centered; {@code false} otherwise
 */
private void packCenterShow(Window window, boolean center) {
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  window.pack();
  if (center) {
    window.setLocation((screenSize.width - window.getWidth()) / 2, (screenSize.height - window.getHeight()) / 2);
  }
  window.setVisible(true);
}

代码示例来源:origin: joel-costigliola/assertj-swing

@RunsInCurrentThread
static @Nonnull Point absoluteCenterOf(@Nonnull Window window) {
 Insets insets = window.getInsets();
 int w = window.getWidth() - (insets.left + insets.right);
 int h = window.getHeight() - (insets.top + insets.bottom);
 int x = window.getX() + insets.left;
 int y = window.getY() + insets.top;
 return new Point(x + (w / 2), y + (h / 2));
}

代码示例来源:origin: org.nuiton.jaxx/jaxx-widgets-about

public void display() {
  setSize((int)(getOwner().getWidth() * 0.7), (int)(getOwner().getHeight() * 0.7));
  SwingUtil.center(getOwner(), this);
  setVisible(true);
}

相关文章

微信公众号

最新文章

更多

Window类方法