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

JPanel Rounded Corners #367

Closed
shaydarebuar opened this issue Aug 5, 2021 · 3 comments
Closed

JPanel Rounded Corners #367

shaydarebuar opened this issue Aug 5, 2021 · 3 comments
Milestone

Comments

@shaydarebuar
Copy link

It is great JPanel have rounded property like other components as well...

Thanks for such amazing LAF.

DevCharly added a commit that referenced this issue Dec 11, 2021
@DevCharly
Copy link
Collaborator

implemented in main branch for v2

There are several ways to use it.

Set panel background color and arc diameter:

panel.setBackground( Color.magenta );
panel.putClientProperty( FlatClientProperties.STYLE, "arc: 8" );

image

Use FlatLineBorder, which also allows specifying insets:

panel.setBackground( Color.magenta );
panel.setBorder( new FlatLineBorder( new Insets( 16, 16, 16, 16 ), Color.blue, 1, 8 ) );

image

Or use styling and let FlatLaf compute colors:

panel.putClientProperty( FlatClientProperties.STYLE,
    "background: tint(@background,50%);" +
    "border: 16,16,16,16,shade(@background,10%),,8" );

image

To support light and dark themes:

panel.putClientProperty( FlatClientProperties.STYLE,
    "[light]background: tint(@background,50%);" +
    "[dark]background: shade(@background,15%);" +
    "[light]border: 16,16,16,16,shade(@background,10%),,8;" +
    "[dark]border: 16,16,16,16,tint(@background,10%),,8" );

image

If you have many places to use same panel style, define it once (after FlatLaf.setup()):

UIManager.put( "[style]Panel.myRoundPanel",
    "[light]background: tint(@background,50%);" +
    "[dark]background: shade(@background,15%);" +
    "[light]border: 16,16,16,16,shade(@background,10%),,8;" +
    "[dark]border: 16,16,16,16,tint(@background,10%),,8" );

and use it:

panel.putClientProperty( FlatClientProperties.STYLE_CLASS, "myRoundPanel" );

Or use own FlatLaf properties files to define such styles.
See Application properties files.

Create FlatLightLaf.properties:

[style]Panel.myRoundPanel= \
    background: tint(@background,50%); \
    border: 16,16,16,16,shade(@background,10%),,8

And create FlatDarkLaf.properties:

[style]Panel.myRoundPanel= \
    background: shade(@background,15%); \
    border: 16,16,16,16,tint(@background,10%),,8

@DevCharly DevCharly added this to the 2.0 milestone Dec 15, 2021
@Langelot0210
Copy link

How to apply gradient color on a Jpanel with FlatLaf?

@DevCharly
Copy link
Collaborator

How to apply gradient color on a Jpanel with FlatLaf?

@Langelot0210 FlatLaf does not support gradient backgrounds.

You have to implement this yourself.
Simply create a subclass of JPanel, override paintComponent(Graphics) method and paint the gradient

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

3 participants