FlatLaf
FlatLaf copied to clipboard
Disabled foreground color for tables
I'd like to suggest the addition of a different foreground color for a JTable when the component is disabled. I've implemented it in a custom look and feel by reacting to the enabled property changes and modifying the foreground color of the table:
public class CustomTableUI extends BasicTableUI implements PropertyChangeListener {
public static ComponentUI createUI(JComponent c) {
return new CustomTableUI();
}
public void installUI(JComponent component) {
super.installUI(component);
JTable table = (JTable) component;
table.addPropertyChangeListener("enabled", this);
}
public void uninstallUI(JComponent component) {
super.uninstallUI(component);
JTable table = (JTable) component;
table.removePropertyChangeListener("enabled", this);
}
public void propertyChange(PropertyChangeEvent event) {
if ("enabled".equals(event.getPropertyName())) {
JTable table = (JTable) event.getSource();
table.setForeground(UIManager.getColor(Boolean.TRUE.equals(event.getNewValue()) ? "Table.foreground" : "Table.disabledForeground"));
}
}
}
That makes sense.
JTable is the only component that does no dim text if disabled.
JTree and JList dim text if disabled.
And even JXTable and JXTreeTable (from SwingX) dim text if disabled.