From 1f2dc1f963f93e60cc9d481be2d0477a018fc649 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 15 May 2018 18:02:33 +0200 Subject: [PATCH] Fix drawing of underline on center-aligned LinkLabel --- .../ui/components/labels/LinkLabel.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/components/labels/LinkLabel.java b/platform/platform-api/src/com/intellij/ui/components/labels/LinkLabel.java index c9e84841d014..45249bce004e 100644 --- a/platform/platform-api/src/com/intellij/ui/components/labels/LinkLabel.java +++ b/platform/platform-api/src/com/intellij/ui/components/labels/LinkLabel.java @@ -177,7 +177,10 @@ public class LinkLabel extends JLabel { @NotNull protected Rectangle getTextBounds() { - return UIUtil.getLabelTextBounds(this); + if (textR.isEmpty()) { + updateLayoutRectangles(); + } + return textR; } protected Color getTextColor() { @@ -211,6 +214,17 @@ public class LinkLabel extends JLabel { private final JBRectangle viewR = new JBRectangle(); protected boolean isInClickableArea(Point pt) { + updateLayoutRectangles(); + if (getIcon() != null) { + iconR.width += getIconTextGap(); //todo[kb] icon at right? + if (iconR.contains(pt)) { + return true; + } + } + return textR.contains(pt); + } + + private void updateLayoutRectangles() { iconR.clear(); textR.clear(); final Insets insets = getInsets(null); @@ -230,13 +244,6 @@ public class LinkLabel extends JLabel { iconR, textR, getIconTextGap()); - if (getIcon() != null) { - iconR.width += getIconTextGap(); //todo[kb] icon at right? - if (iconR.contains(pt)) { - return true; - } - } - return textR.contains(pt); } //for GUI tests