本文整理了Java中java.awt.Window.getLocationOnScreen()
方法的一些代码示例,展示了Window.getLocationOnScreen()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window.getLocationOnScreen()
方法的具体详情如下:
包路径:java.awt.Window
类名称:Window
方法名:getLocationOnScreen
暂无
代码示例来源: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: net.java.openjdk.cacio/cacio-shared
private boolean isMouseInWindowRegion(Window w) {
Point l = w.getLocationOnScreen();
Dimension size = w.getSize();
return l.x <= x && x < (l.x + size.width) && l.y <= y && y < (l.y + size.height);
}
代码示例来源:origin: com.dorkbox/SystemTray-Dorkbox-Util
/**
* Centers a component according to the window location.
*
* @param window The parent window
* @param component A component, usually a dialog
*/
public static
void centerInWindow(final Window window, final Component component) {
Dimension size = window.getSize();
Point loc = window.getLocationOnScreen();
Dimension cmpSize = component.getSize();
loc.x += (size.width - cmpSize.width) / 2;
loc.y += (size.height - cmpSize.height) / 2;
component.setBounds(loc.x, loc.y, cmpSize.width, cmpSize.height);
}
代码示例来源:origin: sdedit/sdedit
public static void centerWindow(Window window, Window parent) {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int width = window.getWidth();
int height = window.getHeight();
int left = Math.max(0,
parent.getLocationOnScreen().x + parent.getSize().width / 2
- width / 2);
left = Math.min(left, screen.width - width);
int top = Math.max(0, parent.getLocationOnScreen().y
+ parent.getSize().height / 2 - height / 2);
top = Math.min(top, screen.height - height);
window.setLocation(left, top);
}
代码示例来源:origin: net.java.dev.jna/jna-platform
public void actionPerformed(ActionEvent e) {
Point location = dragImage.getLocationOnScreen();
Point dst = new Point(origin);
int dx = (dst.x - location.x)/2;
int dy = (dst.y - location.y)/2;
if (dx != 0 || dy != 0) {
location.translate(dx, dy);
move(location);
}
else {
timer.stop();
dispose();
}
}
});
代码示例来源:origin: net.java.dev.jna/platform
public void actionPerformed(ActionEvent e) {
Point location = dragImage.getLocationOnScreen();
Point dst = new Point(origin);
int dx = (dst.x - location.x)/2;
int dy = (dst.y - location.y)/2;
if (dx != 0 || dy != 0) {
location.translate(dx, dy);
move(location);
}
else {
timer.stop();
dispose();
}
}
});
代码示例来源:origin: org.activecomponents.jadex/jadex-commons-gui
/**
* Calculate the middle position of a window relativ to
*/
public static Point calculateMiddlePosition(Window outer, Window win)
{
int rx;
int ry;
if(outer!=null && outer.isVisible())
{
Point p = outer.getLocationOnScreen();
rx = (int)(p.getX()+outer.getWidth()/2);
ry = (int)(p.getY()+outer.getHeight()/2);
}
else
{
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
rx = (int)size.getWidth() / 2;
ry = (int)size.getHeight() / 2;
}
int x = rx - win.getWidth()/2;
int y = ry - win.getHeight()/2;
return new Point(x, y);
}
代码示例来源:origin: org.apache.cayenne.modeler/cayenne-modeler
/**
* Center a window on a parent window
*/
public static void centerWindow(Window parent, Window child) {
Dimension parentSize = parent.getSize();
Dimension childSize = child.getSize();
Point parentLocation = new Point(0, 0);
if (parent.isShowing()) {
parentLocation = parent.getLocationOnScreen();
}
int x = parentLocation.x + parentSize.width / 2 - childSize.width / 2;
int y = parentLocation.y + parentSize.height / 2 - childSize.height / 2;
child.setLocation(x, y);
}
}
代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop
/**
* Hides the findPanel's toplevel window and returns its location.
* If the dispose is true, the findPanel is removed from its parent
* and the toplevel window is disposed.
*
* @param dispose boolean to indicate whether the findPanels toplevel
* window should be disposed.
* @return the location of the window if visible, or the last known
* location.
*/
protected Point hideSharedFindPanel(boolean dispose) {
if (findPanel == null) return null;
Window window = SwingUtilities.getWindowAncestor(findPanel);
Point location = lastFindDialogLocation;
if (window != null) {
// PENDING JW: can't remember why it it removed always?
if (window.isVisible()) {
location = window.getLocationOnScreen();
window.setVisible(false);
}
if (dispose) {
findPanel.getParent().remove(findPanel);
window.dispose();
}
}
return location;
}
代码示例来源:origin: net.sourceforge.mydoggy/mydoggy-plaf
fullScreenBounds.put(window, targetBounds);
Point location = window.getLocationOnScreen();
代码示例来源:origin: org.swinglabs.swingx/swingx-core
/**
* Hides the findPanel's toplevel window and returns its location.
* If the dispose is true, the findPanel is removed from its parent
* and the toplevel window is disposed.
*
* @param dispose boolean to indicate whether the findPanels toplevel
* window should be disposed.
* @return the location of the window if visible, or the last known
* location.
*/
protected Point hideSharedFindPanel(boolean dispose) {
if (findPanel == null) return null;
Window window = SwingUtilities.getWindowAncestor(findPanel);
Point location = lastFindDialogLocation;
if (window != null) {
// PENDING JW: can't remember why it it removed always?
if (window.isVisible()) {
location = window.getLocationOnScreen();
window.setVisible(false);
}
if (dispose) {
findPanel.getParent().remove(findPanel);
window.dispose();
}
}
return location;
}
代码示例来源:origin: org.swinglabs.swingx/swingx-all
/**
* Hides the findPanel's toplevel window and returns its location.
* If the dispose is true, the findPanel is removed from its parent
* and the toplevel window is disposed.
*
* @param dispose boolean to indicate whether the findPanels toplevel
* window should be disposed.
* @return the location of the window if visible, or the last known
* location.
*/
protected Point hideSharedFindPanel(boolean dispose) {
if (findPanel == null) return null;
Window window = SwingUtilities.getWindowAncestor(findPanel);
Point location = lastFindDialogLocation;
if (window != null) {
// PENDING JW: can't remember why it it removed always?
if (window.isVisible()) {
location = window.getLocationOnScreen();
window.setVisible(false);
}
if (dispose) {
findPanel.getParent().remove(findPanel);
window.dispose();
}
}
return location;
}
代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core
/**
* Hides the findPanel's toplevel window and returns its location.
* If the dispose is true, the findPanel is removed from its parent
* and the toplevel window is disposed.
*
* @param dispose boolean to indicate whether the findPanels toplevel
* window should be disposed.
* @return the location of the window if visible, or the last known
* location.
*/
protected Point hideSharedFindPanel(boolean dispose) {
if (findPanel == null) return null;
Window window = SwingUtilities.getWindowAncestor(findPanel);
Point location = lastFindDialogLocation;
if (window != null) {
// PENDING JW: can't remember why it it removed always?
if (window.isVisible()) {
location = window.getLocationOnScreen();
window.setVisible(false);
}
if (dispose) {
findPanel.getParent().remove(findPanel);
window.dispose();
}
}
return location;
}
代码示例来源:origin: com.haulmont.thirdparty/swingx-core
/**
* Hides the findPanel's toplevel window and returns its location.
* If the dispose is true, the findPanel is removed from its parent
* and the toplevel window is disposed.
*
* @param dispose boolean to indicate whether the findPanels toplevel
* window should be disposed.
* @return the location of the window if visible, or the last known
* location.
*/
protected Point hideSharedFindPanel(boolean dispose) {
if (findPanel == null) return null;
Window window = SwingUtilities.getWindowAncestor(findPanel);
Point location = lastFindDialogLocation;
if (window != null) {
// PENDING JW: can't remember why it it removed always?
if (window.isVisible()) {
location = window.getLocationOnScreen();
window.setVisible(false);
}
if (dispose) {
findPanel.getParent().remove(findPanel);
window.dispose();
}
}
return location;
}
代码示例来源:origin: org.apache.cayenne.modeler/cayenne-modeler
/**
* Centers view on parent window.
*/
protected void centerView() {
Window parentWindow = parent.getWindow();
Dimension parentSize = parentWindow.getSize();
Dimension windowSize = getView().getSize();
Point parentLocation = new Point(0, 0);
if (parentWindow.isShowing()) {
parentLocation = parentWindow.getLocationOnScreen();
}
int x = parentLocation.x + parentSize.width / 2 - windowSize.width / 2;
int y = parentLocation.y + parentSize.height / 2 - windowSize.height / 2;
getView().setLocation(x, y);
}
代码示例来源:origin: abbot/abbot
public static void moveFrameRelativeTo(Frame frame, Component relativeTo) {
Point location = RELATIVE_OFFSET;
Window reference = null;
if (relativeTo != null) {
reference = getWindow(relativeTo);
}
if (reference != null) {
location = reference.getLocationOnScreen();
location.translate(RELATIVE_OFFSET.x, RELATIVE_OFFSET.y);
}
frame.setLocation(location);
ensureOnScreen(frame);
}
代码示例来源:origin: zitmen/thunderstorm
/**
* shows the url in the static window, sizes and positions the window
* accordingly
*/
private void showInTextWindow() throws IOException {
window.setVisible(false);
// same height as parent window of the button, positioned next to it on left or right side
Window ancestor = SwingUtilities.getWindowAncestor(this);
window.setPreferredSize(new Dimension(WINDOW_WIDTH, Math.max(ancestor.getHeight(), WINDOW_HEIGHT)));
int screenEnd = ancestor.getGraphicsConfiguration().getBounds().width + ancestor.getGraphicsConfiguration().getBounds().x;
Point ancestorLocation = ancestor.getLocationOnScreen();
if(ancestorLocation.x + ancestor.getWidth() + window.getPreferredSize().width < screenEnd) {
window.setLocation(ancestorLocation.x + ancestor.getWidth(), ancestorLocation.y);
} else {
window.setLocation(ancestorLocation.x - window.getPreferredSize().width, ancestorLocation.y);
}
//set page shown in browser
if(url != null && !url.equals(htmlBrowser.getPage())) {
try {
htmlBrowser.setPage(url);
} catch(Exception e) {
htmlBrowser.setText("Could not load help file");
}
}
window.pack();
window.setVisible(true);
}
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu
private Component getTopLevelAncestor(JComponent s, int x, int y) {
// return s.getTopLevelAncestor();
Component r = s.getTopLevelAncestor();
Point p = SwingUtilities.convertPoint(s, x, y, r);
Rectangle b = r.getBounds();
b.x = b.y = 0;
if (b.contains(p)) {
if (r instanceof Frame) ((Frame) r).toFront();
// System.err.println("TOP="+r.getClass());
return r;
}
p = s.getLocationOnScreen();
p.x += x;
p.y += y;
if (windows_ == null) windows_ = DndLib.getAllWindows();
if (windows_ != null) for (int i = 0; i < windows_.length; i++)
if (windows_[i].isShowing()) {
Point q = windows_[i].getLocationOnScreen();
b = windows_[i].getBounds();
b.x = q.x;
b.y = q.y;
if (b.contains(p)) {
windows_[i].toFront();
return windows_[i];
}
}
return null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-xml-xam-ui
void mouseRelease(MouseEvent e){
if(alreadyDrawn){
if(SplitterLayout.dragee!=this) return;
SplitterLayout.dragee = null;
Point p = wBar.getLocationOnScreen();
SwingUtilities.convertPointFromScreen(p, getParent());
wBar.setVisible(false);
wBar.dispose();
wBar = null;
alreadyDrawn = false;
Rectangle r = getBounds(); // mouse event is relative to this...
r.x += e.getX();
// //System.out.println("mouseReleased converted point "+ p);
// //System.out.println("mouseRelease bounds of this spliltter " + r);
setLocation(p.x, r.y);
setCursor(DEF_CURSOR);
// check to see if we need to move other splitters and hide other
// components that are controlled by the layout
// First -- find what component this one is
checkOtherComponents();
mouseInside = false;
invalidate();
getParent().validate();
SplitterLayout.dragee = null;
}
}
代码示例来源:origin: org.jclarion/clarion-runtime
.getLocation();
Point locationOnScreen = w
.getLocationOnScreen();
r.mouseMove(locationOnScreen.x + 100,
locationOnScreen.y + 10);
内容来源于网络,如有侵权,请联系作者删除!