FlatLaf icon indicating copy to clipboard operation
FlatLaf copied to clipboard

Disabled foreground color for tables

Open ebourg opened this issue 4 years ago • 1 comments

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"));
        }
    }
}

ebourg avatar Sep 17 '21 09:09 ebourg

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.

DevCharly avatar Oct 13 '21 15:10 DevCharly