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

Per component focus border #412

Closed
ebourg opened this issue Nov 3, 2021 · 3 comments
Closed

Per component focus border #412

ebourg opened this issue Nov 3, 2021 · 3 comments

Comments

@ebourg
Copy link
Contributor

ebourg commented Nov 3, 2021

The focus border configured with Component.focusedBorderColor is applied to all components. It would be nice to be able to disable it for some components such as the JScrollPanes.

@DevCharly
Copy link
Collaborator

You can disable focus border for single scroll pane:

Component view = myScrollPane.getViewport().getView();
((JComponent)view).putClientProperty(
    FlatClientProperties.COMPONENT_FOCUS_OWNER,
    (Predicate<JComponent>) c -> false );

@ebourg
Copy link
Contributor Author

ebourg commented Nov 3, 2021

Thank you for the tip, I guess making the scroll pane non focusable would work too, but I was looking for something more like a ScrollPane.focusedBorderColor property overriding the default Component.focusedBorderColor.

@DevCharly
Copy link
Collaborator

There is actually a simple solution.

Create a own border class that changes the color:

public class MyScrollPaneBorder extends FlatBorder {
    public MyScrollPaneBorder() {
        focusedBorderColor = Color.red;
    }
}

And install it:

MyScrollPaneBorder myScrollPaneBorder = new MyScrollPaneBorder();
UIManager.put( "ScrollPane.border", myScrollPaneBorder );
UIManager.put( "Table.scrollPaneBorder", myScrollPaneBorder );

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