From f69b3f56dde57500005b5772ff5c22e0b56b8513 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sun, 10 Nov 2019 00:09:51 +0100 Subject: [PATCH] ToolTip: use anti-aliasing to render multi-line tooltips --- CHANGELOG.md | 1 + .../com/formdev/flatlaf/ui/FlatToolTipUI.java | 2 +- .../java/com/formdev/flatlaf/ui/FlatUIUtils.java | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e63b06bc..590183c91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ FlatLaf Change Log and is no longer interrupted by the scroll buttons. - TabbedPane: Content pane is no longer opaque. Use antialiasing for painting separator and content border. +- ToolTip: Use anti-aliasing to render multi-line tooltips. - JIDE Common Layer: Support `JideTabbedPane`. diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolTipUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolTipUI.java index 9b76ce7cd..6d778db0a 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolTipUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToolTipUI.java @@ -81,7 +81,7 @@ public void paint( Graphics g, JComponent c ) { boolean leftToRight = (comp != null ? comp : c).getComponentOrientation().isLeftToRight(); for( String line : lines ) { y += lineHeight; - g.drawString( line, leftToRight ? x : x2 - SwingUtilities.computeStringWidth( fm, line ), y ); + FlatUIUtils.drawString( c, g, line, leftToRight ? x : x2 - SwingUtilities.computeStringWidth( fm, line ), y ); } } else super.paint( g, c ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java index e7679f9fb..b8c5f748a 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java @@ -256,6 +256,22 @@ public static Path2D createPath( boolean close, double... points ) { } /** + * Draws the given string at the specified location using text properties + * and anti-aliasing hints from the provided component. + * + * Use this method instead of Graphics.drawString() for correct anti-aliasing. + * + * Replacement for SwingUtilities2.drawString() + */ + public static void drawString( JComponent c, Graphics g, String text, int x, int y ) { + JavaCompatibility.drawStringUnderlineCharAt( c, g, text, -1, x, y ); + } + + /** + * Draws the given string at the specified location underlining the specified + * character. The provided component is used to query text properties and + * anti-aliasing hints. + * * Replacement for SwingUtilities2.drawStringUnderlineCharAt() */ public static void drawStringUnderlineCharAt( JComponent c, Graphics g,