Skip to content

Commit

Permalink
ComboBox (not editable): fixed background painted outside of border i…
Browse files Browse the repository at this point in the history
…f round edges are enabled (similar to issue #382; regression since fixing #330 in FlatLaf 1.4)

(cherry picked from commit 02f3239)
  • Loading branch information
DevCharly committed Nov 11, 2021
1 parent 150bab0 commit 0b6df8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ FlatLaf Change Log

#### Fixed bugs

- ComboBox (not editable): Fixed background painted outside of border if round
edges are enabled (client property `JComponent.roundRect` is `true`). (similar
to issue #382; regression since fixing #330 in FlatLaf 1.4)
- Table: Do not select text in cell editor when it gets focus (when
`JTable.surrendersFocusOnKeystroke` is `true`) and
`TextComponent.selectAllOnFocusPolicy` is `once` (the default) or `always`.
Expand Down Expand Up @@ -43,7 +46,7 @@ FlatLaf Change Log
- ComboBox (editable): Fixed wrong border of internal text field under special
circumstances.
- Spinner: Fixed painting of border corners on left side. (issue #382;
regression since FlatLaf 1.4)
regression since fixing #330 in FlatLaf 1.4)
- TableHeader: Do not show resize cursor for last column if resizing last column
is not possible because auto resize mode of table is not off. (issue #332)
- TableHeader: Fixed missing trailing vertical separator line if used in upper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,22 @@ public void update( Graphics g, JComponent c ) {
@Override
@SuppressWarnings( "unchecked" )
public void paintCurrentValue( Graphics g, Rectangle bounds, boolean hasFocus ) {
// apply clipping using rounded rectangle to avoid that renderer paints
// outside of border if combobox uses larger arc for edges
// (e.g. FlatClientProperties.COMPONENT_ROUND_RECT is true)
FlatBorder border = FlatUIUtils.getOutsideFlatBorder( comboBox );
if( border != null ) {
int clipArc = border.getArc( comboBox ) - (border.getLineWidth( comboBox ) * 2);
if( clipArc > 0 ) {
int x = bounds.x;
int width = bounds.width + bounds.height;
if( !comboBox.getComponentOrientation().isLeftToRight() )
x -= bounds.height;
((Graphics2D)g).clip( FlatUIUtils.createComponentRectangle(
x, bounds.y, width, bounds.height, scale( (float) clipArc ) ) );
}
}

paddingBorder.uninstall();

ListCellRenderer<Object> renderer = comboBox.getRenderer();
Expand Down

0 comments on commit 0b6df8b

Please sign in to comment.