From 41817590085b2b6b979480197a41991b60936918 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Mon, 21 Oct 2019 22:12:51 +0200 Subject: [PATCH] right-to-left fixes: -Slider: colored track (if ticks and labels are hidden) was on the left side of the thumb - ToolTip: multi-line text was not aligned to the right (issue #18) --- .../java/com/formdev/flatlaf/ui/FlatSliderUI.java | 12 +++++++++--- .../java/com/formdev/flatlaf/ui/FlatToolTipUI.java | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java index 799f0964..c0945008 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java @@ -170,9 +170,15 @@ public class FlatSliderUI if( slider.getOrientation() == JSlider.HORIZONTAL ) { float y = trackRect.y + (trackRect.height - tw) / 2f; if( enabled && isRoundThumb() ) { - int cw = thumbRect.x + (thumbRect.width / 2) - trackRect.x; - coloredTrack = new RoundRectangle2D.Float( trackRect.x, y, cw, tw, arc, arc ); - track = new RoundRectangle2D.Float( trackRect.x + cw, y, trackRect.width - cw, tw, arc, arc ); + if( slider.getComponentOrientation().isLeftToRight() ) { + int cw = thumbRect.x + (thumbRect.width / 2) - trackRect.x; + coloredTrack = new RoundRectangle2D.Float( trackRect.x, y, cw, tw, arc, arc ); + track = new RoundRectangle2D.Float( trackRect.x + cw, y, trackRect.width - cw, tw, arc, arc ); + } else { + int cw = trackRect.x + trackRect.width - thumbRect.x - (thumbRect.width / 2); + coloredTrack = new RoundRectangle2D.Float( trackRect.x + trackRect.width - cw, y, cw, tw, arc, arc ); + track = new RoundRectangle2D.Float( trackRect.x, y, trackRect.width - cw, tw, arc, arc ); + } } else track = new RoundRectangle2D.Float( trackRect.x, y, trackRect.width, tw, arc, arc ); } else { 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 abdd6e4e..9b76ce7c 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 @@ -74,11 +74,14 @@ public class FlatToolTipUI List lines = FlatLaf.split( ((JToolTip)c).getTipText(), '\n' ); int x = insets.left; + int x2 = c.getWidth() - insets.right; int y = insets.top - fm.getDescent(); int lineHeight = fm.getHeight(); + JComponent comp = ((JToolTip)c).getComponent(); + boolean leftToRight = (comp != null ? comp : c).getComponentOrientation().isLeftToRight(); for( String line : lines ) { y += lineHeight; - g.drawString( line, x, y ); + g.drawString( line, leftToRight ? x : x2 - SwingUtilities.computeStringWidth( fm, line ), y ); } } else super.paint( g, c );