Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled foreground color for tables #387

Open
ebourg opened this issue Sep 17, 2021 · 1 comment
Open

Disabled foreground color for tables #387

ebourg opened this issue Sep 17, 2021 · 1 comment

Comments

@ebourg
Copy link
Contributor

ebourg commented Sep 17, 2021

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"));
        }
    }
}
@DevCharly
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants