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

Buttons: No response to "Disabled" background and text Color settings #79

Closed
zanderson9 opened this issue Sep 17, 2019 · 3 comments
Closed
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@zanderson9
Copy link
Collaborator

With the latest version 1.0.2, I noticed that a disabled button does not respond to the theme settings for color.
I have these entries in UIManager, as an example:
UIManager.put("Button.disabledText", Color.RED);
UIManager.put("Button[disabled].background", Color.BLUE);

But regardless of these settings, the button always appears in Color.Gray (see attached)

Buttons-Disabled

@vincenzopalazzo vincenzopalazzo added enhancement New feature or request good first issue Good for newcomers labels Sep 17, 2019
@vincenzopalazzo
Copy link
Owner

Hi @zanderson9, with all version Material library this bug exists because, the MaterialButtonUI Extends the BasicButtonUI, and BasicButtonUI using this code for paint text

 protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
        AbstractButton b = (AbstractButton) c;
        ButtonModel model = b.getModel();
        FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
        int mnemonicIndex = b.getDisplayedMnemonicIndex();

        /* Draw the Text */
        if(model.isEnabled()) {
            /*** paint the text normally */
            g.setColor(b.getForeground());
            SwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
                                          textRect.x + getTextShiftOffset(),
                                          textRect.y + fm.getAscent() + getTextShiftOffset());
        }
        else {
            /*** paint the text disabled ***/
            g.setColor(b.getBackground().brighter());
            SwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
                                          textRect.x, textRect.y + fm.getAscent());
            g.setColor(b.getBackground().darker());
            SwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex,
                                          textRect.x - 1, textRect.y + fm.getAscent() - 1);
        }
    }

I know this problem, I find it with the test regression, but form moment I don't have a good idea to resolve it, I will work on to find the solution

@zanderson9
Copy link
Collaborator Author

Thank you for this detailed explanation. I understand now why the problem exists.

vincenzopalazzo added a commit that referenced this issue Sep 19, 2019
This release fixed 
- #80
- #79
@vincenzopalazzo
Copy link
Owner

vincenzopalazzo commented Sep 19, 2019

This issue was fixed, now on the constant UIManager the button response well

The constants are

table.put("Button.disabledBackground", COLOR);
table.put("Button.disabledForeground", COLOR);

vincenzopalazzo pushed a commit that referenced this issue Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants