diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java index 4b274f1c..38e3560c 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatClientProperties.java @@ -992,7 +992,28 @@ public interface FlatClientProperties //---- JToggleButton ------------------------------------------------------ /** - * Height of underline if toggle button type is {@link #BUTTON_TYPE_TAB}. + * Placement of underline if toggle button type is {@link #BUTTON_TYPE_TAB} + *

+ * Component {@link javax.swing.JToggleButton}
+ * Value type {@link java.lang.Integer}
+ * Default value {@link SwingConstants#BOTTOM}
+ * SupportedValues: + * + * + * + * + * + * + * + * + * + * + *
PlacementConstantValue
TOP{@link SwingConstants#TOP}{@value SwingConstants#TOP}
LEFT{@link SwingConstants#LEFT}{@value SwingConstants#LEFT}
BOTTOM{@link SwingConstants#BOTTOM}{@value SwingConstants#BOTTOM}
RIGHT{@link SwingConstants#RIGHT}{@value SwingConstants#RIGHT}
+ */ + String TAB_BUTTON_UNDERLINE_PLACEMENT = "JToggleButton.tab.underlinePlacement"; + + /** + * Thickness of underline if toggle button type is {@link #BUTTON_TYPE_TAB}. *

* Component {@link javax.swing.JToggleButton}
* Value type {@link java.lang.Integer} diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java index e238a4f9..3e106ae5 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatToggleButtonUI.java @@ -22,10 +22,7 @@ import java.awt.Component; import java.awt.Graphics; import java.beans.PropertyChangeEvent; import java.util.Map; -import javax.swing.AbstractButton; -import javax.swing.JComponent; -import javax.swing.JToggleButton; -import javax.swing.UIManager; +import javax.swing.*; import javax.swing.plaf.ComponentUI; import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException; @@ -142,6 +139,7 @@ public class FlatToggleButtonUI b.repaint(); break; + case TAB_BUTTON_UNDERLINE_PLACEMENT: case TAB_BUTTON_UNDERLINE_HEIGHT: case TAB_BUTTON_UNDERLINE_COLOR: case TAB_BUTTON_SELECTED_BACKGROUND: @@ -196,11 +194,25 @@ public class FlatToggleButtonUI // paint underline if selected if( selected ) { - int underlineHeight = UIScale.scale( clientPropertyInt( c, TAB_BUTTON_UNDERLINE_HEIGHT, tabUnderlineHeight ) ); + int underlineThickness = UIScale.scale( clientPropertyInt( c, TAB_BUTTON_UNDERLINE_HEIGHT, tabUnderlineHeight ) ); g.setColor( c.isEnabled() ? clientPropertyColor( c, TAB_BUTTON_UNDERLINE_COLOR, tabUnderlineColor ) : tabDisabledUnderlineColor ); - g.fillRect( 0, height - underlineHeight, width, underlineHeight ); + int placement = clientPropertyInt( c, TAB_BUTTON_UNDERLINE_PLACEMENT, SwingConstants.BOTTOM ); + switch (placement) { + case SwingConstants.TOP: + g.fillRect( 0, 0, width, underlineThickness ); + break; + case SwingConstants.LEFT: + g.fillRect( 0, 0, underlineThickness, height ); + break; + case SwingConstants.RIGHT: + g.fillRect( width - underlineThickness, 0, underlineThickness, height ); + break; + case SwingConstants.BOTTOM: + default: + g.fillRect( 0, height - underlineThickness, width, underlineThickness ); + } } } else super.paintBackground( g, c ); diff --git a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/components/FlatToggleButton.java b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/components/FlatToggleButton.java index 226acb12..3190223b 100644 --- a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/components/FlatToggleButton.java +++ b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/components/FlatToggleButton.java @@ -18,7 +18,7 @@ package com.formdev.flatlaf.extras.components; import static com.formdev.flatlaf.FlatClientProperties.*; import java.awt.Color; -import javax.swing.JToggleButton; +import javax.swing.*; import com.formdev.flatlaf.extras.components.FlatButton.ButtonType; /** @@ -116,6 +116,24 @@ public class FlatToggleButton putClientProperty( OUTLINE, outline ); } + /** + * Returns placement of underline if toggle button type is {@link ButtonType#tab}. + * If underline placement is not specified, returns {@link #BOTTOM} as the default + * value. + */ + public int getTabUnderlinePlacement() { + return getClientPropertyInt( TAB_BUTTON_UNDERLINE_PLACEMENT, BOTTOM ); + } + + /** + * Specifies placement of underline if toggle button type is {@link ButtonType#tab}. + * + * @param placement One of the following constants defined in SwingConstants: + * {@link #TOP}, {@link #LEFT}, {@link #BOTTOM}, or {@link #RIGHT}. + */ + public void setTabUnderlinePlacement( int placement ) { + putClientProperty( TAB_BUTTON_UNDERLINE_PLACEMENT, (placement < 0 || placement >= RIGHT) ? null : placement); + } /** * Returns height of underline if toggle button type is {@link ButtonType#tab}.