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

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

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

Window.getBounds介绍

暂无

代码示例

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

private static boolean willPopupBeContained(JPopupMenu popup, Point origin) {
  if (!popup.isShowing()) {
    return false;
  }
  Window w = SwingUtilities.windowForComponent(popup.getInvoker());
  Rectangle r = new Rectangle(origin, popup.getSize());
  return (w != null) && w.getBounds().contains(r);
}

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

/** Tries to resize wizard wisely if needed. Keeps "display inertia" so that
 * wizard is only enlarged, not shrinked, and location is changed only when
 * wizard window exceeds screen bounds after resize.
 */
private void resizeWizard(Window parentWindow, Dimension prevSize) {
  assert SwingUtilities.isEventDispatchThread () : "getComponent() must be called in EQ only.";
  Dimension curSize = data.getIterator(this).current().getComponent().getPreferredSize();
  // only enlarge if needed, don't shrink
  if ((curSize.width > prevSize.width) || (curSize.height > prevSize.height)) {
    Rectangle origBounds = parentWindow.getBounds();
    int newWidth = Math.max(origBounds.width + (curSize.width - prevSize.width), origBounds.width);
    int newHeight = Math.max(origBounds.height + (curSize.height - prevSize.height), origBounds.height);
    Rectangle screenBounds = Utilities.getUsableScreenBounds();
    Rectangle newBounds;
    // don't allow to exceed screen size, center if needed
    if (((origBounds.x + newWidth) > screenBounds.width) || ((origBounds.y + newHeight) > screenBounds.height)) {
      newWidth = Math.min(screenBounds.width, newWidth);
      newHeight = Math.min(screenBounds.height, newHeight);
      newBounds = Utilities.findCenterBounds(new Dimension(newWidth, newHeight));
    } else {
      newBounds = new Rectangle(origBounds.x, origBounds.y, newWidth, newHeight);
    }
    parentWindow.setBounds(newBounds);
    parentWindow.invalidate();
    parentWindow.validate();
    parentWindow.repaint();
  }
}

代码示例来源:origin: com.fifesoft.rtext/fife.common

private boolean getShouldPaintGrip() {
  Rectangle rect = window.getBounds();
  Dimension dim = getToolkit().getScreenSize();
  if((rect.x == rect.y) && (rect.x <= 0) &&
    (rect.x>-20) && (dim.width-20<rect.width) &&
    (dim.width +20 > rect.width))
      return false;
  return true;
}

代码示例来源:origin: net.java.dev.jna/jna-platform

@Override
  public Rectangle getBounds() {
    return getOwner().getBounds();
  }
}

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

button.addActionListener( new ActionListener()
{
  public void actionPerformed(ActionEvent e)
  {
    JButton button = (JButton)e.getSource();
    Window window = SwingUtilities.windowForComponent(button);
    JDialog dialog = new JDialog();
    dialog.setBounds( window.getBounds() );
    dialog.setVisible(true);
  }
});

代码示例来源:origin: net.java.dev.jna/platform

public Rectangle getBounds() {
    return getOwner().getBounds();
  }
}

代码示例来源:origin: cmu-phil/tetrad

/**
 * Sets the location of the window to the middle of the screen
 *
 * @param window - component whos location is set.
 */
private static void setLocation(Window window) {
  Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
  Rectangle bounds = window.getBounds();
  window.setLocation((screenDim.width - bounds.width) / 2,
      (screenDim.height - bounds.height) / 2);
}

代码示例来源:origin: org.scijava/scijava-ui-awt

/** Centers the given window within the specified parent window. */
public static void centerWindow(final Window parent, final Window window) {
  centerWindow(parent.getBounds(), window);
}

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

private void store(Window w) {
  String bounds =
   (String)ConverterRegistry.instance().convert(
    String.class,
    w.getBounds());
  node().node("Windows").put(w.getName() + ".bounds", bounds);
 }
};

代码示例来源:origin: openpreserve/jhove

/**
 *  Center the window at the top of the main screen.
 */
public static void centerTopWindow (Window win)
{
  Rectangle devBounds = mainBounds ();
  Rectangle winBounds = win.getBounds ();
  int lmargin = (devBounds.width - winBounds.width) / 2;
  // Don't go off the edge
  if (lmargin < 0) {
    lmargin = 0;
  }
  win.setLocation (lmargin, 0);
}

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

private static boolean willPopupBeContained(JPopupMenu popup, Point origin) {
  if (!popup.isShowing()) {
    return false;
  }
  Window w = SwingUtilities.windowForComponent (popup.getInvoker());
  Rectangle r = new Rectangle (origin, popup.getSize ());
  return w != null && w.getBounds ().contains (r);
}

代码示例来源:origin: openpreserve/jhove

/**
 *  Center the window on the main screen.
 */
public static void centerWindow (Window win)
{
  Rectangle devBounds = mainBounds ();
  Rectangle winBounds = win.getBounds ();
  int lmargin = (devBounds.width - winBounds.width) / 2;
  int tmargin = (devBounds.height - winBounds.height) / 2;
  // Don't go off the edge
  if (lmargin < 0) {
    lmargin = 0;
  }
  if (tmargin < 0) {
    tmargin = 0;
  }
  win.setLocation (lmargin, tmargin);
}

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

private static boolean willPopupBeContained(JPopupMenu popup, Point origin) {
  if (!popup.isShowing()) {
    return false;
  }
  Window w = SwingUtilities.windowForComponent (popup.getInvoker());
  Rectangle r = new Rectangle (origin, popup.getSize ());
  return w != null && w.getBounds ().contains (r);
}

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

@Override
public void componentMoved(ComponentEvent evt)
{
  if(System.currentTimeMillis() - start < 1000L)
  {
    Rectangle r = win.getBounds();
    if(!windowOpened && r.equals(required))
      return;
    if(!r.equals(desired))
    {
      Log.log(Log.DEBUG,GUIUtilities.class,
        "Window resize blocked: " + win.getBounds());
      win.setBounds(desired);
    }
  }
  win.removeComponentListener(this);
} //}}}

代码示例来源:origin: senbox-org/snap-desktop

@Override
  public void actionPerformed(ActionEvent e) {
    LayerSourceAssistantPane pane = new LayerSourceAssistantPane(SwingUtilities.getWindowAncestor(control),
                                   "Add Layer");
    final Map<String, LayerSourceDescriptor> layerSourceDescriptors1 =
        LayerManager.getDefault().getLayerSourceDescriptors();
    final LayerSourceDescriptor[] layerSourceDescriptors2 =
        layerSourceDescriptors1.values().toArray(new LayerSourceDescriptor[layerSourceDescriptors1.size()]);
    pane.show(new SelectLayerSourceAssistantPage(layerSourceDescriptors2), screenBounds);
    screenBounds = pane.getWindow().getBounds();
  }
}

代码示例来源:origin: groboclown/p4ic4idea

public static void show(@NotNull Project project, @NotNull List<ServerConfig> configs,
    @NotNull ChooseListener listener) {
  ChooseLabelDialog dialog = new ChooseLabelDialog(project, configs, listener);
  dialog.pack();
  final Dimension bounds = dialog.getSize();
  final Rectangle parentBounds = dialog.getOwner().getBounds();
  dialog.setLocation(parentBounds.x + (parentBounds.width - bounds.width) / 2,
      parentBounds.y + (parentBounds.height - bounds.height) / 2);
  dialog.setVisible(true);
}

代码示例来源:origin: org.zaproxy/zap

private void centreOnOwner() {
  Dimension frameSize = this.getSize();
  Rectangle mainrect = getOwner().getBounds();
  int x = mainrect.x + (mainrect.width - frameSize.width) / 2;
  int y = mainrect.y + (mainrect.height - frameSize.height) / 2;
  this.setLocation(x, y);
}

代码示例来源:origin: eu.mihosoft.vrl/vrl

/**
 * Centers a frame on parent frame.
 *
 * @param parent parent frame
 * @param frame the frame to center
 */
public static void centerOnWindow(Window parent, Window frame) {
  Rectangle screenBounds = parent.getBounds();
  int x = screenBounds.x
      + screenBounds.width / 2 - frame.getWidth() / 2;
  int y = screenBounds.y
      + screenBounds.height / 2 - frame.getHeight() / 2;
  frame.setLocation(x, y);
}

代码示例来源:origin: bcdev/beam

@Override
  public void actionPerformed(ActionEvent e) {
    LayerSourceAssistantPane pane = new LayerSourceAssistantPane(SwingUtilities.getWindowAncestor(control),
                                   "Add Layer",
                                   getAppContext());
    LayerSourceDescriptor[] layerSourceDescriptors = BeamUiActivator.getInstance().getLayerSources();
    pane.show(new SelectLayerSourceAssistantPage(layerSourceDescriptors), screenBounds);
    screenBounds = pane.getWindow().getBounds();
  }
}

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

public static void center(final Window window) {
 if (window == null) {
  return;
 }
 final Window owner = window.getOwner();
 if (owner == null || owner.getBounds().equals(new Rectangle(0, 0, 0, 0))) {
  centerToScreen(window);
  return;
 }
 final int x = owner.getX() + owner.getWidth() / 2 - window.getWidth() / 2;
 final int y = owner.getY() + owner.getHeight() / 2 - window.getHeight() / 2;
 window.setLocation(x < 0 ? 0 : x, y < 0 ? 0 : y);
}

相关文章

Window类方法