I'm implementing a dynamic LaF change, and this means that no UI resources should be hard-coded or held on when retrieved from UIManager.
I currently have a lot of code that looks like this throughout my codebase:
panel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, UIManager.getColor("Component.borderColor")));
The code above creates a border that only has one segment on top.
I want to make use of FlatLaf's style client property border, but setting individual insets to 0 has no effect; all four segments are painted anyway.
A more extreme example follows:
field.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("Component.borderColor")),
BorderFactory.createEmptyBorder(6, 8, 6, 8)));
So as a workaround I have to override component's updateUI and set a new border there:
var panel = new JPanel() {
@Override
public void updateUI() {
super.updateUI();
setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, UIManager.getColor("Component.borderColor")))
}
};
Am I missing something? Thanks!
I'm implementing a dynamic LaF change, and this means that no UI resources should be hard-coded or held on when retrieved from
UIManager.I currently have a lot of code that looks like this throughout my codebase:
The code above creates a border that only has one segment on top.
I want to make use of FlatLaf's
styleclient propertyborder, but setting individual insets to0has no effect; all four segments are painted anyway.A more extreme example follows:
So as a workaround I have to override component's
updateUIand set a new border there:Am I missing something? Thanks!