Skip to content

Allow specifying individual border dimensions in border #1114

@ShadelessFox

Description

@ShadelessFox

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions