Closed shaydarebuar closed 2 years ago
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" );
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 ) );
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" );
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" );
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
How to apply gradient color on a Jpanel with FlatLaf?
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
It is great JPanel have rounded property like other components as well...
Thanks for such amazing LAF.