From 6df0cfe14c38349b2a8599dc9017dcc3dc3bd576 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Tue, 25 Jul 2017 19:41:56 +0300 Subject: [PATCH] IDEA-175617 show popup above the expandable field if no space below --- .../com/intellij/ui/ExpandableTextField.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/platform/platform-api/src/com/intellij/ui/ExpandableTextField.java b/platform/platform-api/src/com/intellij/ui/ExpandableTextField.java index 5de5c7879dc9..ea0063ca04f1 100644 --- a/platform/platform-api/src/com/intellij/ui/ExpandableTextField.java +++ b/platform/platform-api/src/com/intellij/ui/ExpandableTextField.java @@ -129,6 +129,21 @@ public final class ExpandableTextField extends JTextField implements Expandable JBInsets.addTo(size, insets); JBInsets.addTo(size, pane.getInsets()); if (size.width - MINIMAL_WIDTH < getWidth()) size.width = getWidth(); + + Point location = new Point(0, 0); + SwingUtilities.convertPointToScreen(location, this); + Rectangle screen = ScreenUtil.getScreenRectangle(this); + int bottom = screen.y - location.y + screen.height; + if (bottom < size.height) { + int top = location.y - screen.y + getHeight(); + if (top < bottom) { + size.height = bottom; + } + else { + if (size.height > top) size.height = top; + location.y -= size.height - getHeight(); + } + } pane.setPreferredSize(size); pane.setViewportBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right)); @@ -158,7 +173,7 @@ public final class ExpandableTextField extends JTextField implements Expandable return false; } }).createPopup(); - popup.show(new RelativePoint(this, new Point(0, 0))); + popup.show(new RelativePoint(location)); } private static void copyCaretPosition(JTextComponent source, JTextComponent destination) {