TabbedPane: support background color for selected tabs

This commit is contained in:
Karl Tauber
2019-12-13 23:14:41 +01:00
parent c4183ada11
commit 65fbcedaa4
3 changed files with 15 additions and 2 deletions

View File

@@ -1,6 +1,11 @@
FlatLaf Change Log FlatLaf Change Log
================== ==================
## Unreleased
- TabbedPane: Support background color for selected tabs.
## 0.21 ## 0.21
- ScrollBar: Show decrease/increase arrow buttons if client property - ScrollBar: Show decrease/increase arrow buttons if client property

View File

@@ -53,6 +53,7 @@ import com.formdev.flatlaf.FlatLaf;
* @uiDefault TabbedPane.foreground Color * @uiDefault TabbedPane.foreground Color
* @uiDefault TabbedPane.shadow Color used for scroll arrows and cropped line * @uiDefault TabbedPane.shadow Color used for scroll arrows and cropped line
* @uiDefault TabbedPane.disabledForeground Color * @uiDefault TabbedPane.disabledForeground Color
* @uiDefault TabbedPane.selectedBackground Color optional
* @uiDefault TabbedPane.selectedForeground Color * @uiDefault TabbedPane.selectedForeground Color
* @uiDefault TabbedPane.underlineColor Color * @uiDefault TabbedPane.underlineColor Color
* @uiDefault TabbedPane.disabledUnderlineColor Color * @uiDefault TabbedPane.disabledUnderlineColor Color
@@ -73,6 +74,7 @@ public class FlatTabbedPaneUI
extends BasicTabbedPaneUI extends BasicTabbedPaneUI
{ {
protected Color disabledForeground; protected Color disabledForeground;
protected Color selectedBackground;
protected Color selectedForeground; protected Color selectedForeground;
protected Color underlineColor; protected Color underlineColor;
protected Color disabledUnderlineColor; protected Color disabledUnderlineColor;
@@ -95,6 +97,7 @@ public class FlatTabbedPaneUI
super.installDefaults(); super.installDefaults();
disabledForeground = UIManager.getColor( "TabbedPane.disabledForeground" ); disabledForeground = UIManager.getColor( "TabbedPane.disabledForeground" );
selectedBackground = UIManager.getColor( "TabbedPane.selectedBackground" );
selectedForeground = UIManager.getColor( "TabbedPane.selectedForeground" ); selectedForeground = UIManager.getColor( "TabbedPane.selectedForeground" );
underlineColor = UIManager.getColor( "TabbedPane.underlineColor" ); underlineColor = UIManager.getColor( "TabbedPane.underlineColor" );
disabledUnderlineColor = UIManager.getColor( "TabbedPane.disabledUnderlineColor" ); disabledUnderlineColor = UIManager.getColor( "TabbedPane.disabledUnderlineColor" );
@@ -124,6 +127,7 @@ public class FlatTabbedPaneUI
super.uninstallDefaults(); super.uninstallDefaults();
disabledForeground = null; disabledForeground = null;
selectedBackground = null;
selectedForeground = null; selectedForeground = null;
underlineColor = null; underlineColor = null;
disabledUnderlineColor = null; disabledUnderlineColor = null;
@@ -262,7 +266,9 @@ public class FlatTabbedPaneUI
? hoverColor ? hoverColor
: (enabled && isSelected && tabPane.hasFocus() : (enabled && isSelected && tabPane.hasFocus()
? focusColor ? focusColor
: tabPane.getBackgroundAt( tabIndex )) ); : (selectedBackground != null && enabled && isSelected
? selectedBackground
: tabPane.getBackgroundAt( tabIndex ))) );
g.fillRect( x, y, w, h ); g.fillRect( x, y, w, h );
} }
@@ -334,7 +340,7 @@ public class FlatTabbedPaneUI
} }
/** /**
* Actually does the nearly the same as super.paintContentBorder() but * Actually does nearly the same as super.paintContentBorder() but
* - not using UIManager.getColor("TabbedPane.contentAreaColor") to be GUI builder friendly * - not using UIManager.getColor("TabbedPane.contentAreaColor") to be GUI builder friendly
* - not invoking paintContentBorder*Edge() methods * - not invoking paintContentBorder*Edge() methods
* - repaint selection * - repaint selection

View File

@@ -229,6 +229,8 @@ SplitPaneDivider.oneTouchHoverArrowColor=#ff0000
#---- TabbedPane ---- #---- TabbedPane ----
TabbedPane.disabledForeground=#777777 TabbedPane.disabledForeground=#777777
TabbedPane.selectedBackground=#0f0
TabbedPane.selectedForeground=#00f
TabbedPane.underlineColor=#4A88C7 TabbedPane.underlineColor=#4A88C7
TabbedPane.disabledUnderlineColor=#7a7a7a TabbedPane.disabledUnderlineColor=#7a7a7a
TabbedPane.hoverColor=#eeeeee TabbedPane.hoverColor=#eeeeee