Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ public UIDefaults getDefaults() {
"RadioButton.disabledText",
"RadioButtonMenuItem.disabledForeground",
"Spinner.disabledForeground",
"Table.disabledForeground",
"ToggleButton.disabledText" );
putDefaults( defaults, defaults.getColor( "textText" ),
"DesktopIcon.foreground" );
Expand Down
37 changes: 37 additions & 0 deletions flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicTableUI;
import javax.swing.table.JTableHeader;
import com.formdev.flatlaf.FlatClientProperties;
Expand Down Expand Up @@ -78,6 +79,7 @@
* @uiDefault Table.showVerticalLines boolean
* @uiDefault Table.showTrailingVerticalLine boolean
* @uiDefault Table.intercellSpacing Dimension
* @uiDefault Table.disabledForeground Color
* @uiDefault Table.selectionInactiveBackground Color
* @uiDefault Table.selectionInactiveForeground Color
*
Expand All @@ -102,6 +104,8 @@ public class FlatTableUI
/** @since 1.6 */ @Styleable protected boolean showTrailingVerticalLine;
protected Dimension intercellSpacing;

private Color foreground;
/** @since 2 */ @Styleable protected Color disabledForeground;
@Styleable protected Color selectionBackground;
@Styleable protected Color selectionForeground;
@Styleable protected Color selectionInactiveBackground;
Expand All @@ -112,6 +116,7 @@ public class FlatTableUI
@Styleable protected Color cellFocusColor;
@Styleable protected boolean showCellFocusIndicator;

private Color oldDisabledForeground;
private boolean oldShowHorizontalLines;
private boolean oldShowVerticalLines;
private Dimension oldIntercellSpacing;
Expand All @@ -127,6 +132,7 @@ public static ComponentUI createUI( JComponent c ) {
public void installUI( JComponent c ) {
super.installUI( c );

updateForeground();
installStyle();
}

Expand All @@ -139,6 +145,8 @@ protected void installDefaults() {
showTrailingVerticalLine = UIManager.getBoolean( "Table.showTrailingVerticalLine" );
intercellSpacing = UIManager.getDimension( "Table.intercellSpacing" );

foreground = UIManager.getColor( "Table.foreground" );
disabledForeground = UIManager.getColor( "Table.disabledForeground" );
selectionBackground = UIManager.getColor( "Table.selectionBackground" );
selectionForeground = UIManager.getColor( "Table.selectionForeground" );
selectionInactiveBackground = UIManager.getColor( "Table.selectionInactiveBackground" );
Expand Down Expand Up @@ -169,11 +177,15 @@ protected void installDefaults() {
protected void uninstallDefaults() {
super.uninstallDefaults();

foreground = null;
disabledForeground = null;
selectionBackground = null;
selectionForeground = null;
selectionInactiveBackground = null;
selectionInactiveForeground = null;

oldDisabledForeground = null;

oldStyleValues = null;

// restore old show horizontal/vertical lines (if not modified)
Expand Down Expand Up @@ -203,6 +215,10 @@ protected void installListeners() {
table.revalidate();
table.repaint();
break;

case "enabled":
updateForeground();
break;
}
};
table.addPropertyChangeListener( propertyChangeListener );
Expand Down Expand Up @@ -248,13 +264,17 @@ protected void installStyle() {

/** @since 2 */
protected void applyStyle( Object style ) {
oldDisabledForeground = disabledForeground;

Color oldSelectionBackground = selectionBackground;
Color oldSelectionForeground = selectionForeground;
Color oldSelectionInactiveBackground = selectionInactiveBackground;
Color oldSelectionInactiveForeground = selectionInactiveForeground;

oldStyleValues = FlatStylingSupport.parseAndApply( oldStyleValues, style, this::applyStyleProperty );

updateForeground();

// update selection background
if( selectionBackground != oldSelectionBackground ) {
Color selBg = table.getSelectionBackground();
Expand Down Expand Up @@ -285,6 +305,23 @@ public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
return FlatStylingSupport.getAnnotatedStyleableInfos( this );
}

// similar to FlatTextFieldUI.updateBackground()
private void updateForeground() {
Color oldForeground = table.getForeground();
if( !(oldForeground instanceof UIResource) )
return;

// do not update foreground if it currently has a unknown color (assigned from outside)
if( oldForeground != foreground &&
oldForeground != disabledForeground &&
oldForeground != oldDisabledForeground )
return;

Color newForeground = table.isEnabled() ? foreground : disabledForeground;
if( newForeground != oldForeground )
table.setForeground( newForeground );
}

/**
* Toggle selection colors from focused to inactive and vice versa.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ void table() {

Map<String, Class<?>> expected = expectedMap(
"showTrailingVerticalLine", boolean.class,
"disabledForeground", Color.class,
"selectionBackground", Color.class,
"selectionForeground", Color.class,
"selectionInactiveBackground", Color.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ void table() {
FlatTableUI ui = (FlatTableUI) c.getUI();

ui.applyStyle( "showTrailingVerticalLine: true" );
ui.applyStyle( "disabledForeground: #fff" );
ui.applyStyle( "selectionBackground: #fff" );
ui.applyStyle( "selectionForeground: #fff" );
ui.applyStyle( "selectionInactiveBackground: #fff" );
Expand Down
1 change: 1 addition & 0 deletions flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ Table.cellMargins 2,3,2,3 javax.swing.plaf.InsetsUIResource [UI]
Table.cellNoFocusBorder [lazy] 2,3,2,3 false com.formdev.flatlaf.ui.FlatTableCellBorder$Default [UI] lineColor=#000000 HSL 0 0 0 javax.swing.plaf.ColorUIResource [UI] lineThickness=1.000000
Table.consistentHomeEndKeyBehavior true
Table.descendingSortIcon [lazy] 10,5 com.formdev.flatlaf.icons.FlatDescendingSortIcon [UI]
Table.disabledForeground #8c8c8c HSL 0 0 55 javax.swing.plaf.ColorUIResource [UI]
Table.dropCellBackground [lazy] #3c588b HSL 219 40 39 javax.swing.plaf.ColorUIResource [UI]
Table.dropCellForeground [lazy] #bbbbbb HSL 0 0 73 javax.swing.plaf.ColorUIResource [UI]
Table.dropLineColor [lazy] #6d8ac0 HSL 219 40 59 javax.swing.plaf.ColorUIResource [UI]
Expand Down
1 change: 1 addition & 0 deletions flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ Table.cellMargins 2,3,2,3 javax.swing.plaf.InsetsUIResource [UI]
Table.cellNoFocusBorder [lazy] 2,3,2,3 false com.formdev.flatlaf.ui.FlatTableCellBorder$Default [UI] lineColor=#000000 HSL 0 0 0 javax.swing.plaf.ColorUIResource [UI] lineThickness=1.000000
Table.consistentHomeEndKeyBehavior true
Table.descendingSortIcon [lazy] 10,5 com.formdev.flatlaf.icons.FlatDescendingSortIcon [UI]
Table.disabledForeground #8c8c8c HSL 0 0 55 javax.swing.plaf.ColorUIResource [UI]
Table.dropCellBackground [lazy] #3f8fd9 HSL 209 67 55 javax.swing.plaf.ColorUIResource [UI]
Table.dropCellForeground [lazy] #ffffff HSL 0 0 100 javax.swing.plaf.ColorUIResource [UI]
Table.dropLineColor [lazy] #6aa7e1 HSL 209 66 65 javax.swing.plaf.ColorUIResource [UI]
Expand Down
1 change: 1 addition & 0 deletions flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ Table.cellMargins 2,3,2,3 javax.swing.plaf.InsetsUIResource [UI]
Table.cellNoFocusBorder [lazy] 2,3,2,3 false com.formdev.flatlaf.ui.FlatTableCellBorder$Default [UI] lineColor=#ff0000 HSL 0 100 50 javax.swing.plaf.ColorUIResource [UI] lineThickness=1.000000
Table.consistentHomeEndKeyBehavior true
Table.descendingSortIcon [lazy] 10,5 com.formdev.flatlaf.icons.FlatDescendingSortIcon [UI]
Table.disabledForeground #000088 HSL 240 100 27 javax.swing.plaf.ColorUIResource [UI]
Table.dropCellBackground #ff0000 HSL 0 100 50 javax.swing.plaf.ColorUIResource [UI]
Table.dropCellForeground #00ff00 HSL 120 100 50 javax.swing.plaf.ColorUIResource [UI]
Table.dropLineColor #0000ff HSL 240 100 50 javax.swing.plaf.ColorUIResource [UI]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ Table.cellMargins
Table.cellNoFocusBorder
Table.consistentHomeEndKeyBehavior
Table.descendingSortIcon
Table.disabledForeground
Table.dropCellBackground
Table.dropCellForeground
Table.dropLineColor
Expand Down