/** * Sets the location of this window relative to the given rectangle. * * @param r The visual position of the caret (in screen coordinates). */ public void setLocationRelativeTo(Rectangle r) { // Multi-monitor support - make sure the completion window (and // description window, if applicable) both fit in the same window in // a multi-monitor environment. To do this, we decide which monitor // the rectangle "r" is in, and use that one (just pick top-left corner // as the defining point). Rectangle screenBounds = Util.getScreenBoundsForPoint(r.x, r.y); //Dimension screenSize = tooltip.getToolkit().getScreenSize(); // Try putting our stuff "below" the caret first. int y = r.y + r.height + 5; // Get x-coordinate of completions. Try to align left edge with the // caret first. int x = r.x; if (x<screenBounds.x) { x = screenBounds.x; } else if (x+getWidth()>screenBounds.x+screenBounds.width) { // completions don't fit x = screenBounds.x + screenBounds.width - getWidth(); } setLocation(x, y); }
/** * Sets the location of this tool tip relative to the given rectangle. * * @param r The visual position of the caret (in screen coordinates). */ public void setLocationRelativeTo(Rectangle r) { // Multi-monitor support - make sure the completion window (and // description window, if applicable) both fit in the same window in // a multi-monitor environment. To do this, we decide which monitor // the rectangle "r" is in, and use that one (just pick top-left corner // as the defining point). Rectangle screenBounds = Util.getScreenBoundsForPoint(r.x, r.y); //Dimension screenSize = tooltip.getToolkit().getScreenSize(); // Try putting our stuff "above" the caret first. int y = r.y - 5 - tooltip.getHeight(); if (y<0) { y = r.y + r.height + 5; } // Get x-coordinate of completions. Try to align left edge with the // caret first. int x = r.x; if (x<screenBounds.x) { x = screenBounds.x; } else if (x+tooltip.getWidth()>screenBounds.x+screenBounds.width) { // completions don't fit x = screenBounds.x + screenBounds.width - tooltip.getWidth(); } tooltip.setLocation(x, y); }
Rectangle screenBounds = Util.getScreenBoundsForPoint(r.x, r.y);
Rectangle screenBounds = Util.getScreenBoundsForPoint(p.x, p.y);