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

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

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

Window.getSize介绍

暂无

代码示例

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

protected void centerWindow(Window win) {
 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
 // If larger than screen, reduce window width or height
 if (screenDim.width < win.getSize().width) {
  win.setSize(screenDim.width, win.getSize().height);
 }
 if (screenDim.height < win.getSize().height) {
  win.setSize(win.getSize().width, screenDim.height);
 }
 // Center Frame, Dialogue or Window on screen
 int x = (screenDim.width - win.getSize().width) / 2;
 int y = (screenDim.height - win.getSize().height) / 2;
 win.setLocation(x, y);
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Sets the location of the specified window so that it is centered on screen.
 *
 * @param window The window to be centered.
 */
public static void centerWindowOnScreen(Window window) {
  final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  final Dimension size = window.getSize();
  if (size.height > screenSize.height) {
    size.height = screenSize.height;
  }
  if (size.width > screenSize.width) {
    size.width = screenSize.width;
  }
  window.setLocation((screenSize.width - size.width) / 2,
      (screenSize.height - size.height) / 2);
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Centers the window over a component (usually another window).
 * The window must already have been sized.
 */
public static void centerWindowOnComponent(Window window, Component over) {
  if ((over == null) || !over.isShowing()) {
    centerWindowOnScreen(window);
    return;
  }
  Point parentLocation = over.getLocationOnScreen();
  Dimension parentSize = over.getSize();
  Dimension size = window.getSize();
  // Center it.
  int x = parentLocation.x + (parentSize.width - size.width) / 2;
  int y = parentLocation.y + (parentSize.height - size.height) / 2;
  // Now, make sure it's onscreen
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  // This doesn't actually work on the Mac, where the screen
  // doesn't necessarily start at 0,0
  if (x + size.width > screenSize.width)
    x = screenSize.width - size.width;
  if (x < 0)
    x = 0;
  if (y + size.height > screenSize.height)
    y = screenSize.height - size.height;
  if (y < 0)
    y = 0;
  window.setLocation(x, y);
}

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

private static void doCentre(Window dialog, Dimension parentDim) {
  Dimension dialogDim = dialog.getSize();
  int x = Math.max(0, parentDim.width / 2 - dialogDim.width / 2);
  int y = Math.max(0, parentDim.height / 2 - dialogDim.height / 2);
  dialog.setLocation(x, y);
}

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

private static void doShowCentred(Window parent, Window dialog) {
  if (parent == null) {
    doCentre(dialog, Toolkit.getDefaultToolkit().getScreenSize());
  } else {
    doCentre(dialog, parent.getSize());
  }
  dialog.setVisible(true);
}

代码示例来源: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: org.seamless/seamless-swing

public static Window center(Window w, Window reference) {
  double refCenterX = reference.getX() + (reference.getSize().getWidth()/2);
  double refCenterY = reference.getY() + (reference.getSize().getHeight()/2);
  int newX = (int) (refCenterX - (w.getSize().getWidth()/2));
  int newY = (int) (refCenterY - (w.getSize().getHeight()/2));
  w.setLocation(newX, newY);
  return w;
}

代码示例来源:origin: ribomation/DroidAtScreen1

public static void placeInCenterScreen(Window win) {
  Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
  Dimension frame = win.getSize();
  win.setLocation((screen.width - frame.width) / 2, (screen.height - frame.height) / 2);
}

代码示例来源:origin: org.geotools/gt-swing

private static void doCentre(Window dialog, Dimension parentDim) {
  Dimension dialogDim = dialog.getSize();
  int x = Math.max(0, parentDim.width / 2 - dialogDim.width / 2);
  int y = Math.max(0, parentDim.height / 2 - dialogDim.height / 2);
  dialog.setLocation(x, y);
}

代码示例来源:origin: org.apache.directory/com.springsource.org.apache.directory.server.core

private void centerOnScreen( Window window )
{
  Dimension frameSize = window.getSize();
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  frameSize.height = ( ( frameSize.height > screenSize.height ) ? screenSize.height : frameSize.height );
  frameSize.width = ( ( frameSize.width > screenSize.width ) ? screenSize.width : frameSize.width );
  window.setLocation( ( screenSize.width - frameSize.width ) / 2, ( screenSize.height - frameSize.height ) / 2 );
}

代码示例来源:origin: de.sciss/scisslib

public void mousePressed( MouseEvent e )
{
  final Window win = SwingUtilities.getWindowAncestor( e.getComponent() );
  if( win != null ) {
    initialMouse    = e.getPoint();
    SwingUtilities.convertPointToScreen( initialMouse, e.getComponent() );
    initialSize        = win.getSize();
  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/skinlf

/**
 * Description of the Method
 *
 * @param w  Description of Parameter
 */
public static void centerOnScreen(Window w) {
 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 Dimension size = w.getSize();
 w.setLocation((screenSize.width - size.width) / 2,
   (screenSize.height - size.height) / 2);
}

代码示例来源:origin: org.appdapter/org.appdapter.lib.gui

/**
 * Moves the given window to the center of the screen
 */
public static void centerWindow(Window win) {
  Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
  Dimension dim = win.getSize();
  win.setLocation((screen.width / 2) - (dim.width / 2), (screen.height / 2) - (dim.height / 2));
}

代码示例来源:origin: com.darwinsys/darwinsys-api

/** Centre a Window, Frame, JFrame, Dialog, etc. */
public static void centre(final Window w) {
  // After packing a Frame or Dialog, centre it on the screen.
  Dimension us = w.getSize(), 
    them = Toolkit.getDefaultToolkit().getScreenSize();
  int newX = (them.width - us.width) / 2;
  int newY = (them.height- us.height)/ 2;
  w.setLocation(newX, newY);
}

代码示例来源:origin: ribomation/DroidAtScreen1

public static void placeInUpperLeftScreen(Window win) {
  Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
  Dimension frame = win.getSize();
  win.setLocation(screen.width / 4 - frame.width / 2, screen.height / 4 - frame.height / 2);
}

代码示例来源:origin: com.l2fprod.common/l2fprod-common-shared

public static void centerOnScreen(Window window) {
 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 Dimension size = window.getSize();
 window.setLocation(
  (screenSize.width - size.width) / 2,
  (screenSize.height - size.height) / 2);
}

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

public static void centerOnComponet(Window target, JComponent parent) {
 Dimension targetSize = target.getSize();
 Point location = parent.getLocationOnScreen();
 Dimension sourceSize = parent.getSize();
 Point sourceCenter = new Point(location.x + sourceSize.width / 2, location.y + sourceSize.height / 2);
 Point frameLocation = new Point(sourceCenter.x - targetSize.width / 2, sourceCenter.y - targetSize.height / 2);
 target.setLocation(frameLocation);
}

代码示例来源:origin: org.geotools/gt-swing

private static void doShowCentred(Window parent, Window dialog) {
  if (parent == null) {
    doCentre(dialog, Toolkit.getDefaultToolkit().getScreenSize());
  } else {
    doCentre(dialog, parent.getSize());
  }
  dialog.setVisible(true);
}

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

@Override
public void windowClosed(WindowEvent e) {
  if (e.getSource() == gui) {
    return;
  }
  popoutDisposed(getChannelFromWindow(e.getSource()));
  if (savePopoutAttributes) {
    Window window = e.getWindow();
    dialogsAttributes.add(0, new LocationAndSize(
        window.getLocation(), window.getSize()));
  }
}

代码示例来源: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);
}

相关文章

Window类方法