mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 15:27:16 -06:00
TabbedPane: fixed scaling of client property "JTabbedPane.tabHeight"; avoid storing scaled values in UI delegate
This commit is contained in:
@@ -97,7 +97,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault TabbedPane.shadow Color used for scroll arrows and cropped line
|
* @uiDefault TabbedPane.shadow Color used for scroll arrows and cropped line
|
||||||
* @uiDefault TabbedPane.textIconGap int
|
* @uiDefault TabbedPane.textIconGap int
|
||||||
* @uiDefault TabbedPane.tabInsets Insets
|
* @uiDefault TabbedPane.tabInsets Insets
|
||||||
* @uiDefault TabbedPane.selectedTabPadInsets Insets
|
* @uiDefault TabbedPane.selectedTabPadInsets Insets unused
|
||||||
* @uiDefault TabbedPane.tabAreaInsets Insets
|
* @uiDefault TabbedPane.tabAreaInsets Insets
|
||||||
* @uiDefault TabbedPane.tabsOverlapBorder boolean
|
* @uiDefault TabbedPane.tabsOverlapBorder boolean
|
||||||
* @uiDefault TabbedPane.tabRunOverlay int
|
* @uiDefault TabbedPane.tabRunOverlay int
|
||||||
@@ -152,6 +152,7 @@ public class FlatTabbedPaneUI
|
|||||||
protected Color tabSeparatorColor;
|
protected Color tabSeparatorColor;
|
||||||
protected Color contentAreaColor;
|
protected Color contentAreaColor;
|
||||||
|
|
||||||
|
private int textIconGapUnscaled;
|
||||||
protected int tabHeight;
|
protected int tabHeight;
|
||||||
protected int tabSelectionHeight;
|
protected int tabSelectionHeight;
|
||||||
protected int contentSeparatorHeight;
|
protected int contentSeparatorHeight;
|
||||||
@@ -215,6 +216,7 @@ public class FlatTabbedPaneUI
|
|||||||
tabSeparatorColor = UIManager.getColor( "TabbedPane.tabSeparatorColor" );
|
tabSeparatorColor = UIManager.getColor( "TabbedPane.tabSeparatorColor" );
|
||||||
contentAreaColor = UIManager.getColor( "TabbedPane.contentAreaColor" );
|
contentAreaColor = UIManager.getColor( "TabbedPane.contentAreaColor" );
|
||||||
|
|
||||||
|
textIconGapUnscaled = UIManager.getInt( "TabbedPane.textIconGap" );
|
||||||
tabHeight = UIManager.getInt( "TabbedPane.tabHeight" );
|
tabHeight = UIManager.getInt( "TabbedPane.tabHeight" );
|
||||||
tabSelectionHeight = UIManager.getInt( "TabbedPane.tabSelectionHeight" );
|
tabSelectionHeight = UIManager.getInt( "TabbedPane.tabSelectionHeight" );
|
||||||
contentSeparatorHeight = UIManager.getInt( "TabbedPane.contentSeparatorHeight" );
|
contentSeparatorHeight = UIManager.getInt( "TabbedPane.contentSeparatorHeight" );
|
||||||
@@ -228,12 +230,7 @@ public class FlatTabbedPaneUI
|
|||||||
moreTabsButtonToolTipText = UIManager.getString( "TabbedPane.moreTabsButtonToolTipText", l );
|
moreTabsButtonToolTipText = UIManager.getString( "TabbedPane.moreTabsButtonToolTipText", l );
|
||||||
|
|
||||||
// scale
|
// scale
|
||||||
textIconGap = scale( textIconGap );
|
textIconGap = scale( textIconGapUnscaled );
|
||||||
tabInsets = scale( tabInsets );
|
|
||||||
selectedTabPadInsets = scale( selectedTabPadInsets );
|
|
||||||
tabAreaInsets = scale( tabAreaInsets );
|
|
||||||
tabHeight = scale( tabHeight );
|
|
||||||
tabSelectionHeight = scale( tabSelectionHeight );
|
|
||||||
|
|
||||||
// replace focus forward/backward traversal keys with TAB/Shift+TAB because
|
// replace focus forward/backward traversal keys with TAB/Shift+TAB because
|
||||||
// the default also includes Ctrl+TAB/Ctrl+Shift+TAB, which we need to switch tabs
|
// the default also includes Ctrl+TAB/Ctrl+Shift+TAB, which we need to switch tabs
|
||||||
@@ -517,6 +514,9 @@ public class FlatTabbedPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int calculateTabWidth( int tabPlacement, int tabIndex, FontMetrics metrics ) {
|
protected int calculateTabWidth( int tabPlacement, int tabIndex, FontMetrics metrics ) {
|
||||||
|
// update textIconGap before used in super class
|
||||||
|
textIconGap = scale( textIconGapUnscaled );
|
||||||
|
|
||||||
int tabWidth = super.calculateTabWidth( tabPlacement, tabIndex, metrics ) - 3 /* was added by superclass */;
|
int tabWidth = super.calculateTabWidth( tabPlacement, tabIndex, metrics ) - 3 /* was added by superclass */;
|
||||||
if( isTabClosable( tabIndex ) )
|
if( isTabClosable( tabIndex ) )
|
||||||
tabWidth += closeIcon.getIconWidth();
|
tabWidth += closeIcon.getIconWidth();
|
||||||
@@ -525,16 +525,21 @@ public class FlatTabbedPaneUI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int calculateTabHeight( int tabPlacement, int tabIndex, int fontHeight ) {
|
protected int calculateTabHeight( int tabPlacement, int tabIndex, int fontHeight ) {
|
||||||
int tabHeight = clientPropertyInt( tabPane, TABBED_PANE_TAB_HEIGHT, this.tabHeight );
|
int tabHeight = scale( clientPropertyInt( tabPane, TABBED_PANE_TAB_HEIGHT, this.tabHeight ) );
|
||||||
return Math.max( tabHeight, super.calculateTabHeight( tabPlacement, tabIndex, fontHeight ) - 2 /* was added by superclass */ );
|
return Math.max( tabHeight, super.calculateTabHeight( tabPlacement, tabIndex, fontHeight ) - 2 /* was added by superclass */ );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Insets getTabInsets( int tabPlacement, int tabIndex ) {
|
protected Insets getTabInsets( int tabPlacement, int tabIndex ) {
|
||||||
Object value = getTabClientProperty( tabIndex, TABBED_PANE_TAB_INSETS );
|
Object value = getTabClientProperty( tabIndex, TABBED_PANE_TAB_INSETS );
|
||||||
return (value instanceof Insets)
|
return scale( (value instanceof Insets)
|
||||||
? scale( (Insets) value )
|
? (Insets) value
|
||||||
: super.getTabInsets( tabPlacement, tabIndex );
|
: super.getTabInsets( tabPlacement, tabIndex ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Insets getSelectedTabPadInsets( int tabPlacement ) {
|
||||||
|
return new Insets( 0, 0, 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -549,6 +554,9 @@ public class FlatTabbedPaneUI
|
|||||||
// Giving it large values clips painting of the cropped edge and makes it invisible.
|
// Giving it large values clips painting of the cropped edge and makes it invisible.
|
||||||
currentTabAreaInsets.top = currentTabAreaInsets.left = -10000;
|
currentTabAreaInsets.top = currentTabAreaInsets.left = -10000;
|
||||||
|
|
||||||
|
// scale insets (before adding leading/trailing component sizes)
|
||||||
|
insets = scale( insets );
|
||||||
|
|
||||||
// increase insets for wrap layout if using leading/trailing components
|
// increase insets for wrap layout if using leading/trailing components
|
||||||
if( tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT ) {
|
if( tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT ) {
|
||||||
if( leadingComponent != null ) {
|
if( leadingComponent != null ) {
|
||||||
@@ -765,6 +773,7 @@ public class FlatTabbedPaneUI
|
|||||||
Insets contentInsets = getContentBorderInsets( tabPlacement );
|
Insets contentInsets = getContentBorderInsets( tabPlacement );
|
||||||
|
|
||||||
// paint underline selection
|
// paint underline selection
|
||||||
|
int tabSelectionHeight = scale( this.tabSelectionHeight );
|
||||||
switch( tabPlacement ) {
|
switch( tabPlacement ) {
|
||||||
case TOP:
|
case TOP:
|
||||||
default:
|
default:
|
||||||
@@ -871,6 +880,16 @@ public class FlatTabbedPaneUI
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void layoutLabel( int tabPlacement, FontMetrics metrics, int tabIndex, String title, Icon icon,
|
||||||
|
Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected )
|
||||||
|
{
|
||||||
|
// update textIconGap before used in super class
|
||||||
|
textIconGap = scale( textIconGapUnscaled );
|
||||||
|
|
||||||
|
super.layoutLabel( tabPlacement, metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int tabForCoordinate( JTabbedPane pane, int x, int y ) {
|
public int tabForCoordinate( JTabbedPane pane, int x, int y ) {
|
||||||
if( moreTabsButton != null ) {
|
if( moreTabsButton != null ) {
|
||||||
|
|||||||
@@ -300,7 +300,7 @@ public class FlatContainerTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void smallerTabHeightChanged() {
|
private void smallerTabHeightChanged() {
|
||||||
Integer tabHeight = smallerTabHeightCheckBox.isSelected() ? 20 : null;
|
Integer tabHeight = smallerTabHeightCheckBox.isSelected() ? 26 : null;
|
||||||
putTabbedPanesClientProperty( TABBED_PANE_TAB_HEIGHT, tabHeight );
|
putTabbedPanesClientProperty( TABBED_PANE_TAB_HEIGHT, tabHeight );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user