Java Code Examples for javax.swing.JComponent#getLocationOnScreen()

The following examples show how to use javax.swing.JComponent#getLocationOnScreen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockingWindowManagerTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void assertAbove(DockingWindowManager dwm, ComponentProvider p1, ComponentProvider p2) {
	ComponentPlaceholder ph1 = dwm.getActivePlaceholder(p1);
	ComponentPlaceholder ph2 = dwm.getActivePlaceholder(p2);

	ComponentNode n1 = ph1.getNode();
	ComponentNode n2 = ph2.getNode();

	JComponent c1 = n1.getComponent();
	JComponent c2 = n2.getComponent();

	Point l1 = c1.getLocationOnScreen();
	Point l2 = c2.getLocationOnScreen();
	assertTrue(
		"Provider is not above the other provider.  " + p1.getName() + " / " + p2.getName(),
		l1.y < l2.y);
}
 
Example 2
Source File: DockingWindowManagerTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void assertTotheRight(DockingWindowManager dwm, ComponentProvider p1,
		ComponentProvider p2) {
	ComponentPlaceholder ph1 = dwm.getActivePlaceholder(p1);
	ComponentPlaceholder ph2 = dwm.getActivePlaceholder(p2);

	ComponentNode n1 = ph1.getNode();
	ComponentNode n2 = ph2.getNode();

	JComponent c1 = n1.getComponent();
	JComponent c2 = n2.getComponent();

	Point l1 = c1.getLocationOnScreen();
	Point l2 = c2.getLocationOnScreen();
	assertTrue("Provider is not to the right of the other provider.  " + p1.getName() + " / " +
		p2.getName(), l1.x > l2.x);
}
 
Example 3
Source File: DockingWindowManagerTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void assertStacked(DockingWindowManager dwm, ComponentProvider... providers) {

		Integer x = null;
		Integer y = null;

		for (ComponentProvider p : providers) {

			ComponentPlaceholder ph = dwm.getActivePlaceholder(p);
			ComponentNode n = ph.getNode();
			JComponent c = n.getComponent();
			Point l = c.getLocationOnScreen();

			if (x == null) {
				x = l.x;
				y = l.y;
			}
			else {
				assertEquals("Providers are not stacked together", x.intValue(), l.x);
				assertEquals("Providers are not stacked together", y.intValue(), l.y);
			}

		}
	}
 
Example 4
Source File: BasicPopoverVisibility.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Return true if the mouse is currently over the argument.
 */
protected boolean isRollover(JComponent jc) {
	if (!jc.isShowing())
		return false;
	Point p = jc.getLocationOnScreen();
	int w = jc.getWidth();
	int h = jc.getHeight();

	Point mouse = MouseInfo.getPointerInfo().getLocation();

	return mouse.x >= p.x && mouse.y >= p.y && mouse.x < p.x + w
			&& mouse.y < p.y + h;
}
 
Example 5
Source File: DatePicker.java    From LGoodDatePicker with MIT License 5 votes vote down vote up
/**
 * zSetPopupLocation, This calculates and sets the appropriate location for the popup windows,
 * for both the DatePicker and the TimePicker.
 */
static void zSetPopupLocation(CustomPopup popup, int defaultX, int defaultY, JComponent picker,
        JComponent verticalFlipReference, int verticalFlipDistance, int bottomOverlapAllowed) {
    // Gather some variables that we will need.
    Window topWindowOrNull = SwingUtilities.getWindowAncestor(picker);
    Rectangle workingArea = InternalUtilities.getScreenWorkingArea(topWindowOrNull);
    int popupWidth = popup.getBounds().width;
    int popupHeight = popup.getBounds().height;
    // Calculate the default rectangle for the popup.
    Rectangle popupRectangle = new Rectangle(defaultX, defaultY, popupWidth, popupHeight);
    // If the popup rectangle is below the bottom of the working area, then move it upwards by 
    // the minimum amount which will ensure that it will never cover the picker component.
    if (popupRectangle.getMaxY() > (workingArea.getMaxY() + bottomOverlapAllowed)) {
        popupRectangle.y = verticalFlipReference.getLocationOnScreen().y - popupHeight
                - verticalFlipDistance;
    }
    // Confine the popup to be within the working area.
    if (popupRectangle.getMaxX() > (workingArea.getMaxX())) {
        popupRectangle.x -= (popupRectangle.getMaxX() - workingArea.getMaxX());
    }
    if (popupRectangle.getMaxY() > (workingArea.getMaxY() + bottomOverlapAllowed)) {
        popupRectangle.y -= (popupRectangle.getMaxY() - workingArea.getMaxY());
    }
    if (popupRectangle.x < workingArea.x) {
        popupRectangle.x += (workingArea.x - popupRectangle.x);
    }
    if (popupRectangle.y < workingArea.y) {
        popupRectangle.y += (workingArea.y - popupRectangle.y);
    }
    // Set the location of the popup.
    popup.setLocation(popupRectangle.x, popupRectangle.y);
}
 
Example 6
Source File: Validator.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void repaintBadge(JComponent field) {
    Point p = field.getLocationOnScreen();
    SwingUtilities.convertPointFromScreen(p, this);
    
    int x = p.x - warningIcon.getWidth() / 2;
    int y = (int) (p.y + field.getHeight() - warningIcon.getHeight() / 1.5);
    
    repaint(x, y, warningIcon.getWidth(), warningIcon.getHeight());
}
 
Example 7
Source File: AbstractBox.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
public Point2D getAbsoluteLocation() {
  Point2D result = null;
  JComponent jc = getContainerResolve();
  if (jc != null) {
    result = new java.awt.Point(jc.getLocationOnScreen());
    result.setLocation(result.getX() + getX(), result.getY() + getY());
  }
  return result;
}
 
Example 8
Source File: StandardMenu.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
public void atMouse(JComponent jComponent) {
    Point myMouse = DisplayHelper.getMouseLocation();
    Point myPoint = jComponent.getLocationOnScreen();
    designAndGetJPopupMenu().show(jComponent, myMouse.x - myPoint.x, myMouse.y - myPoint.y);
}