mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
ToggleButton: made underline placement configurable
Supported values: TOP, LEFT, BOTTOM, or RIGHT
This commit is contained in:
@@ -992,7 +992,28 @@ public interface FlatClientProperties
|
|||||||
//---- JToggleButton ------------------------------------------------------
|
//---- 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}
|
||||||
|
* <p>
|
||||||
|
* <strong>Component</strong> {@link javax.swing.JToggleButton}<br>
|
||||||
|
* <strong>Value type</strong> {@link java.lang.Integer}<br>
|
||||||
|
* <strong>Default value</strong> {@link SwingConstants#BOTTOM}<br>
|
||||||
|
* <strong>SupportedValues:</strong>
|
||||||
|
* <table>
|
||||||
|
* <thead>
|
||||||
|
* <tr><td>Placement</td><td>Constant</td><td>Value</td></tr>
|
||||||
|
* </thead>
|
||||||
|
* <tbody>
|
||||||
|
* <tr><td>TOP</td><td>{@link SwingConstants#TOP}</td><td>{@value SwingConstants#TOP}</td></tr>
|
||||||
|
* <tr><td>LEFT</td><td>{@link SwingConstants#LEFT}</td><td>{@value SwingConstants#LEFT}</td></tr>
|
||||||
|
* <tr><td>BOTTOM</td><td>{@link SwingConstants#BOTTOM}</td><td>{@value SwingConstants#BOTTOM}</td></tr>
|
||||||
|
* <tr><td>RIGHT</td><td>{@link SwingConstants#RIGHT}</td><td>{@value SwingConstants#RIGHT}</td></tr>
|
||||||
|
* </tbody>
|
||||||
|
* </table>
|
||||||
|
*/
|
||||||
|
String TAB_BUTTON_UNDERLINE_PLACEMENT = "JToggleButton.tab.underlinePlacement";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thickness of underline if toggle button type is {@link #BUTTON_TYPE_TAB}.
|
||||||
* <p>
|
* <p>
|
||||||
* <strong>Component</strong> {@link javax.swing.JToggleButton}<br>
|
* <strong>Component</strong> {@link javax.swing.JToggleButton}<br>
|
||||||
* <strong>Value type</strong> {@link java.lang.Integer}
|
* <strong>Value type</strong> {@link java.lang.Integer}
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ import java.awt.Component;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.*;
|
||||||
import javax.swing.JComponent;
|
|
||||||
import javax.swing.JToggleButton;
|
|
||||||
import javax.swing.UIManager;
|
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
||||||
@@ -142,6 +139,7 @@ public class FlatToggleButtonUI
|
|||||||
b.repaint();
|
b.repaint();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TAB_BUTTON_UNDERLINE_PLACEMENT:
|
||||||
case TAB_BUTTON_UNDERLINE_HEIGHT:
|
case TAB_BUTTON_UNDERLINE_HEIGHT:
|
||||||
case TAB_BUTTON_UNDERLINE_COLOR:
|
case TAB_BUTTON_UNDERLINE_COLOR:
|
||||||
case TAB_BUTTON_SELECTED_BACKGROUND:
|
case TAB_BUTTON_SELECTED_BACKGROUND:
|
||||||
@@ -196,11 +194,25 @@ public class FlatToggleButtonUI
|
|||||||
|
|
||||||
// paint underline if selected
|
// paint underline if selected
|
||||||
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()
|
g.setColor( c.isEnabled()
|
||||||
? clientPropertyColor( c, TAB_BUTTON_UNDERLINE_COLOR, tabUnderlineColor )
|
? clientPropertyColor( c, TAB_BUTTON_UNDERLINE_COLOR, tabUnderlineColor )
|
||||||
: tabDisabledUnderlineColor );
|
: 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
|
} else
|
||||||
super.paintBackground( g, c );
|
super.paintBackground( g, c );
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package com.formdev.flatlaf.extras.components;
|
|||||||
|
|
||||||
import static com.formdev.flatlaf.FlatClientProperties.*;
|
import static com.formdev.flatlaf.FlatClientProperties.*;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import javax.swing.JToggleButton;
|
import javax.swing.*;
|
||||||
import com.formdev.flatlaf.extras.components.FlatButton.ButtonType;
|
import com.formdev.flatlaf.extras.components.FlatButton.ButtonType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,6 +116,24 @@ public class FlatToggleButton
|
|||||||
putClientProperty( OUTLINE, outline );
|
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}.
|
* Returns height of underline if toggle button type is {@link ButtonType#tab}.
|
||||||
|
|||||||
Reference in New Issue
Block a user