JFormDesigner / FlatLaf

FlatLaf - Swing Look and Feel (with Darcula/IntelliJ themes support)
https://www.formdev.com/flatlaf/
Apache License 2.0
3.34k stars 266 forks source link

ToggleButton.selectedForeground not working for HTML text #848

Closed mariusflorinelcristian closed 4 months ago

mariusflorinelcristian commented 4 months ago

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 commented 4 months ago

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
mariusflorinelcristian commented 1 month ago

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 commented 4 weeks ago

... 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.