@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); } });
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); }
/** * 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); }
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); }
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(); } } });
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(); } } });
/** * 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); }
/** * 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); } }
/** * 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; }
fullScreenBounds.put(window, targetBounds); Point location = window.getLocationOnScreen();
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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); }
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); }
/** * 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); }
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; }
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; } }
.getLocation(); Point locationOnScreen = w .getLocationOnScreen(); r.mouseMove(locationOnScreen.x + 100, locationOnScreen.y + 10);