After #1017 released on 3.6.1 the button background and foreground colors are not being displayed in certain states depending on how they were set up.
Using setters works normally, but using the style or style class does not.
Sample code:
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatLightLaf;
import com.formdev.flatlaf.extras.components.FlatButton;
import javax.swing.*;
import java.awt.*;
import java.util.function.Predicate;
class Scratch {
public static void main(String[] args) {
FlatLightLaf.setup();
SwingUtilities.invokeLater(Scratch::showFrame);
}
private static void showFrame() {
var b1 = new FlatButton();
b1.setText("No background unless hovered");
b1.setStyle("buttonType: borderless; background: #1588f3; foreground: #fff;");
// Using the setter instead works
// b1.setButtonType(FlatButton.ButtonType.borderless);
// b1.setBackground(new Color(0x1588f3));
// b1.setForeground(new Color(0xffffff));
var b2 = new FlatButton();
b2.setText("No background when focused");
b2.putClientProperty(FlatClientProperties.COMPONENT_FOCUS_OWNER, (Predicate<JComponent>) c -> true);
b2.setStyle("background: #219453; foreground: #fff;");
// Using the setter instead works
// b2.setBackground(new Color(0x219453));
// b2.setForeground(new Color(0xffffff));
var frame = new JFrame();
var contentPane = frame.getContentPane();
contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
contentPane.add(b1);
contentPane.add(b2);
frame.setSize(300, 100);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
After #1017 released on
3.6.1the button background and foreground colors are not being displayed in certain states depending on how they were set up.Using setters works normally, but using the style or style class does not.
Sample code: