本文整理了Java中java.awt.Window.getLocation()
方法的一些代码示例,展示了Window.getLocation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window.getLocation()
方法的具体详情如下:
包路径:java.awt.Window
类名称:Window
方法名:getLocation
暂无
代码示例来源: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: JetBrains/ideavim
final Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(), rootPane);
final Window window = SwingUtilities.getWindowAncestor(myParent);
final Point windowPos = window.getLocation();
pos.translate(windowPos.x, windowPos.y);
final Insets windowInsets = window.getInsets();
代码示例来源: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: stackoverflow.com
JButton button = (JButton)arg0.getSource();
Window frame = SwingUtilities.windowForComponent( button );
Rectangle bounds = frame.getLocation();
代码示例来源:origin: stackoverflow.com
Component component = e.getComponent();
Window window = SwingUtilities.windowForComponent( component );
Point location = window.getLocation();
代码示例来源:origin: stackoverflow.com
Window win = SwingUtilities.getWindowAncestor(someComponent);
Point ownerLoc = win.getLocation();
代码示例来源:origin: com.darwinsys/darwinsys-api
/** Save the X and Y locations in Preferences node provided.
*/
public static void setSavedLocation(
final Preferences pNode, final Window w) {
Point where = w.getLocation();
int x = (int)where.getX();
pNode.putInt("mainwindow.x", Math.max(0, x));
int y = (int)where.getY();
pNode.putInt("mainwindow.y", Math.max(0, y));
}
代码示例来源:origin: IanDarwin/darwinsys-api
/** Save the X and Y locations in Preferences node provided.
*/
public static void setSavedLocation(
final Preferences pNode, final Window w) {
Point where = w.getLocation();
int x = (int)where.getX();
pNode.putInt("mainwindow.x", Math.max(0, x));
int y = (int)where.getY();
pNode.putInt("mainwindow.y", Math.max(0, y));
}
代码示例来源:origin: abbot/abbot
/** Make the given {@link JToolBar} float. */
public void actionFloat(Component c) {
Window w = SwingUtilities.getWindowAncestor(c);
Point where = w.getLocation();
actionFloat(c, where.x, where.y);
}
代码示例来源:origin: joel-costigliola/assertj-swing
@RunsInCurrentThread
@Nonnull private static Pair<Window, Point> ancestorAndLocation(final @Nonnull JToolBar toolBar) {
Window window = getWindowAncestor(toolBar);
return Pair.of(window, window.getLocation());
}
代码示例来源:origin: org.swinglabs.swingx/swingx-all
/**
* <p/>
* Returns the <code>Point</code> at which a window should be placed in
* order to be staggered slightly from another "origin" window to
* ensure that the title areas of both windows remain visible to the user.
* </p>
*
* @param originWindow Window from which the staggered location will be calculated
*
* @return location staggered from the upper left location of the origin
* window
*/
public static Point getPointForStaggering(Window originWindow) {
Point origin = originWindow.getLocation();
Insets insets = originWindow.getInsets();
origin.x += insets.top;
origin.y += insets.top;
return origin;
}
代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-common
/**
* <p/>
* Returns the <code>Point</code> at which a window should be placed in
* order to be staggered slightly from another "origin" window to
* ensure that the title areas of both windows remain visible to the user.
* </p>
*
* @param originWindow Window from which the staggered location will be calculated
*
* @return location staggered from the upper left location of the origin
* window
*/
public static Point getPointForStaggering(Window originWindow) {
Point origin = originWindow.getLocation();
Insets insets = originWindow.getInsets();
origin.x += insets.top;
origin.y += insets.top;
return origin;
}
代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop
/**
* <p/>
* Returns the <code>Point</code> at which a window should be placed in
* order to be staggered slightly from another "origin" window to
* ensure that the title areas of both windows remain visible to the user.
* </p>
*
* @param originWindow Window from which the staggered location will be calculated
*
* @return location staggered from the upper left location of the origin
* window
*/
public static Point getPointForStaggering(Window originWindow) {
Point origin = originWindow.getLocation();
Insets insets = originWindow.getInsets();
origin.x += insets.top;
origin.y += insets.top;
return origin;
}
代码示例来源:origin: de.sciss/scisslib
public void mousePressed( MouseEvent e )
{
final Window win = SwingUtilities.getWindowAncestor( e.getComponent() );
final GraphicsDevice[] devs;
if( win != null ) {
initialMouse = e.getPoint();
SwingUtilities.convertPointToScreen( initialMouse, e.getComponent() );
initialLoc = win.getLocation();
devs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
bounds = devs[ 0 ].getDefaultConfiguration().getBounds();
for( int i = 1; i < devs.length; i++ ) {
bounds = bounds.union( devs[ i ].getDefaultConfiguration().getBounds() );
}
}
}
代码示例来源:origin: chatty/chatty
/**
* Save the window attributes for a single window.
*
* @param window The window to save the attributes for
*/
private void saveWindowState(Window window) {
// Only save state when window state was actually set during this
// this session at least once
if (!locationSet.contains(window) && window != primaryWindow) {
return;
}
// Should still save whether it was open
StateItem item = windows.get(window);
Point location = window.getLocation();
String state = location.x+","+location.y;
Dimension size = window.getSize();
state += ";"+size.width+","+size.height;
state += ";"+(window.isVisible() ? "1" : "0");
settings.mapPut(SETTING, item.id, state);
}
代码示例来源:origin: hneemann/Digital
/**
* Registers a new window.
* If an old window with the same id is found, its position and size is set to the new window.
* After that the old window is disposed.
*
* @param id the id of the window
* @param window the window itself
* @param <T> the type of the window
* @return the window for chained calls
*/
public <T extends Window> T register(String id, T window) {
if (windows.containsKey(id)) {
Window oldWindow = windows.get(id);
window.setLocation(oldWindow.getLocation());
window.setSize(oldWindow.getSize());
oldWindow.dispose();
}
windows.put(id, window);
return window;
}
代码示例来源:origin: abbot/abbot
/** Returns whether one of the upper corners of the given window is
* accessible.
*/
public static boolean onScreen(Window w) {
return onScreen(w.getLocation())
|| onScreen(new Point(w.getX() + w.getWidth()-1, w.getY()));
}
代码示例来源: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: org.opentcs.thirdparty.jhotdraw/jhotdraw
@Override
public void componentMoved(ComponentEvent evt) {
Window owner = getOwner();
Point newLocation = owner.getLocation();
if (!newLocation.equals(oldLocation)) {
setLocation(
newLocation.x + (owner.getWidth() - getWidth()) / 2,
newLocation.y + owner.getInsets().top);
shiftBackLocation = null;
oldLocation = newLocation;
}
}
};
代码示例来源:origin: chatty/chatty
private void setInitialLocationAndSize(UserInfo dialog) {
Point targetLocation = dummyWindow.getLocation();
if (dummyWindow.getWidth() == 0) {
// Since size (and location) has not been set from the settings,
// move window according to actual dialog size
targetLocation.translate(- dialog.getWidth() / 2, - dialog.getHeight() / 2);
}
if (isLocationUsed(targetLocation)) {
targetLocation.translate(20, 20);
}
dialog.setSize(dummyWindow.getSize());
dialog.setLocation(targetLocation);
dialog.addComponentListener(closeListener);
}
内容来源于网络,如有侵权,请联系作者删除!