Panel: rounded background of panel with rounded corners is now painted even if panel is not opaque (issue #840)

This commit is contained in:
Karl Tauber
2024-05-20 18:57:19 +02:00
parent 3f3ef6b24f
commit bbbdd7e4d3
2 changed files with 27 additions and 24 deletions

View File

@@ -9,6 +9,8 @@ FlatLaf Change Log
indeterminate progress bar UI or using JProgressBar.setIndeterminate(false) indeterminate progress bar UI or using JProgressBar.setIndeterminate(false)
not on AWT thread, because this may throw NPE in FlatProgressBarUI.paint(). not on AWT thread, because this may throw NPE in FlatProgressBarUI.paint().
(issues #841 and #830) (issues #841 and #830)
- Panel: Rounded background of panel with rounded corners is now painted even if
panel is not opaque. (issue #840)
## 3.4.1 ## 3.4.1
@@ -20,7 +22,7 @@ FlatLaf Change Log
- TabbedPane: Fixed swapped back and forward scroll buttons when using - TabbedPane: Fixed swapped back and forward scroll buttons when using
`TabbedPane.scrollButtonsPlacement = trailing` (regression in FlatLaf 3.3). `TabbedPane.scrollButtonsPlacement = trailing` (regression in FlatLaf 3.3).
- Fixed missing window top border on Windows 10 in "full window content" mode. - Fixed missing window top border on Windows 10 in "full window content" mode.
(issue 809) (issue #809)
- Extras: - Extras:
- `FlatSVGIcon` color filters now support linear gradients. (PR #817) - `FlatSVGIcon` color filters now support linear gradients. (PR #817)
- `FlatSVGIcon`: Use log level `CONFIG` instead of `SEVERE` and allow - `FlatSVGIcon`: Use log level `CONFIG` instead of `SEVERE` and allow
@@ -65,7 +67,7 @@ FlatLaf Change Log
- Fonts: Updated **Inter** to - Fonts: Updated **Inter** to
[v4.0](https://github.com/rsms/inter/releases/tag/v4.0). [v4.0](https://github.com/rsms/inter/releases/tag/v4.0).
- Table: Select all text in cell editor when starting editing using `F2` key. - Table: Select all text in cell editor when starting editing using `F2` key.
(issue 652) (issue #652)
#### Fixed bugs #### Fixed bugs
@@ -93,7 +95,7 @@ FlatLaf Change Log
#### Fixed bugs #### Fixed bugs
- Button and ToggleButton: Selected buttons did not use explicitly set - Button and ToggleButton: Selected buttons did not use explicitly set
foreground color. (issue 756) foreground color. (issue #756)
- FileChooser: Catch NPE in Java 21 when getting icon for `.exe` files that use - FileChooser: Catch NPE in Java 21 when getting icon for `.exe` files that use
default Windows exe icon. (see default Windows exe icon. (see
[JDK-8320692](https://bugs.openjdk.org/browse/JDK-8320692)) [JDK-8320692](https://bugs.openjdk.org/browse/JDK-8320692))
@@ -846,7 +848,7 @@ FlatLaf Change Log
- Native window decorations (Windows 10 only): - Native window decorations (Windows 10 only):
- Fixed occasional application crash in `flatlaf-windows.dll`. (issue #357) - Fixed occasional application crash in `flatlaf-windows.dll`. (issue #357)
- When window is initially shown, fill background with window background color - When window is initially shown, fill background with window background color
(instead of white), which avoids flickering in dark themes. (issue 339) (instead of white), which avoids flickering in dark themes. (issue #339)
- When resizing a window at the right/bottom edge, then first fill the new - When resizing a window at the right/bottom edge, then first fill the new
space with the window background color (instead of black) before the layout space with the window background color (instead of black) before the layout
is updated. is updated.

View File

@@ -160,29 +160,30 @@ public class FlatPanelUI
@Override @Override
public void update( Graphics g, JComponent c ) { public void update( Graphics g, JComponent c ) {
int arc = (this.arc >= 0)
? this.arc
: ((c.getBorder() instanceof FlatLineBorder)
? ((FlatLineBorder)c.getBorder()).getArc()
: 0);
// fill background // fill background
if( c.isOpaque() ) { if( c.isOpaque() ) {
int width = c.getWidth();
int height = c.getHeight();
int arc = (this.arc >= 0)
? this.arc
: ((c.getBorder() instanceof FlatLineBorder)
? ((FlatLineBorder)c.getBorder()).getArc()
: 0);
// fill background with parent color to avoid garbage in rounded corners
if( arc > 0 )
FlatUIUtils.paintParentBackground( g, c );
g.setColor( c.getBackground() );
if( arc > 0 ) { if( arc > 0 ) {
// fill rounded rectangle if having rounded corners // fill background with parent color to avoid garbage in rounded corners
Object[] oldRenderingHints = FlatUIUtils.setRenderingHints( g ); FlatUIUtils.paintParentBackground( g, c );
FlatUIUtils.paintComponentBackground( (Graphics2D) g, 0, 0, width, height, } else {
0, UIScale.scale( arc ) ); g.setColor( c.getBackground() );
FlatUIUtils.resetRenderingHints( g, oldRenderingHints ); g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
} else }
g.fillRect( 0, 0, width, height ); }
// fill rounded rectangle if having rounded corners
if( arc > 0 ) {
g.setColor( c.getBackground() );
Object[] oldRenderingHints = FlatUIUtils.setRenderingHints( g );
FlatUIUtils.paintComponentBackground( (Graphics2D) g, 0, 0, c.getWidth(), c.getHeight(),
0, UIScale.scale( arc ) );
FlatUIUtils.resetRenderingHints( g, oldRenderingHints );
} }
paint( g, c ); paint( g, c );