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

ToggleButton.selectedForeground not working for HTML text #848

Closed
mariusflorinelcristian opened this issue May 24, 2024 · 3 comments
Closed
Milestone

Comments

@mariusflorinelcristian
Copy link

mariusflorinelcristian commented May 24, 2024

Hi,
It seems that for a selected JToggleButton foreground is not applied if the button has HTML text.
This could be the same problem as the one reported in ​https://github.com/JFormDesigner/FlatLaf/issues/756.
I've tested with the latest version (3.4.1) like below:

public class Main {
    public static void main(String[] args) {
        FlatLightLaf.setup();
        UIManager.put("ToggleButton.selectedForeground", Color.green);

        JFrame frame = new JFrame("JToggleButton FlatLaf Bug");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        JToggleButton normal = new JToggleButton("Normal");
        JToggleButton html = new JToggleButton("<html>HTML text</html>");
        JToggleButton html2 = new JToggleButton("<html><body>"
                + "<font color='red'>Red HTML</font> on <br>two lines</body></html>");

        normal.setSelected(true);
        html.setSelected(true);
        html2.setSelected(true);
        panel.add(normal);
        panel.add(html);
        panel.add(html2);

        frame.add(panel);
        frame.setSize(300, 200);
        frame.setVisible(true);
    }
}

I've expected to see all buttons with GREEN foreground, if they are selected, but only the normal button looks as expected.
Same happens if the properties are set in the properties file.

Also, maybe the subject for another ticket, there is no possibility to define the border, hover and pressed colors for a selected JToggleButton.

Thanks,
Cristi

DevCharly added a commit that referenced this issue May 30, 2024
…ound` and `[Toggle]Button.pressedForeground` did not work for HTML text (issue #848)
DevCharly added a commit that referenced this issue May 30, 2024
@DevCharly
Copy link
Collaborator

thanks for reporting. Fixed in latest 3.5-SNAPSHOT: https://github.com/JFormDesigner/

...there is no possibility to define the border, hover and pressed colors for a selected JToggleButton.

Implemented in latest 3.5-SNAPSHOT.

New properties are (for JButton and JToggleButton):

Button.pressedBorderColor
Button.selectedBorderColor
Button.disabledSelectedBorderColor
Button.focusedSelectedBorderColor
Button.hoverSelectedBorderColor
Button.pressedSelectedBorderColor

Button.default.pressedBorderColor

@DevCharly DevCharly added this to the 3.5 milestone May 31, 2024
@mariusflorinelcristian
Copy link
Author

mariusflorinelcristian commented Aug 23, 2024

Thank you Charly for fixing the selected JToggleButton foreground when it has an HTML text.

I've also tested the new properties for JButton and JToggleButton in 3.5.1:

Button.pressedBorderColor
Button.selectedBorderColor
Button.disabledSelectedBorderColor
Button.focusedSelectedBorderColor
Button.hoverSelectedBorderColor
Button.pressedSelectedBorderColor

Button.default.pressedBorderColor

These properties are really useful for selecting the border color. Foreground/background JToggleButton properties that are available for the Button (e.g. ToggleButton.disabled[focused|hover|pressed]selectedForeground[Background]) are not available for the JToggleButton.

Thank you very much for your work.

@DevCharly
Copy link
Collaborator

... Foreground/background JToggleButton properties that are available for the Button (e.g. ToggleButton.disabled[focused|hover|pressed]selectedForeground[Background]) are not available for the JToggleButton.

JToggleButton uses same properties as JButton for button border properties.
See https://www.formdev.com/flatlaf/components/borders/#flatbuttonborder

If you really need separate border properties for JToggleButton, you could create a subclass of FlatButtonBorder (e.g. MyToggleButtonBorder), update color related fields in constructor and then register that class as JToggleButton border.
E.g. ToggleButton.border = somepackage.MyToggleButtonBorder in FlatLaf properties,
or UIManager.put( "ToggleButton.border", new somepackage.MyToggleButtonBorder() ) in code.

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