mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 06:50:56 +03:00
CheckBox and RadioButton: do not fill background if used as cell renderer, except if cell is selected or has different background color (issue #311)
This commit is contained in:
@@ -26,6 +26,8 @@ FlatLaf Change Log
|
|||||||
|
|
||||||
#### Fixed bugs
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- CheckBox and RadioButton: Do not fill background if used as cell renderer,
|
||||||
|
except if cell is selected or has different background color. (issue #311)
|
||||||
- DesktopPane:
|
- DesktopPane:
|
||||||
- Fixed missing preview of iconified internal frames in dock when using a
|
- Fixed missing preview of iconified internal frames in dock when using a
|
||||||
custom desktop manager. (PR #294)
|
custom desktop manager. (PR #294)
|
||||||
@@ -202,7 +204,7 @@ FlatLaf Change Log
|
|||||||
- CheckBox and RadioButton: Fill component background as soon as background
|
- CheckBox and RadioButton: Fill component background as soon as background
|
||||||
color is different to default background color, even if component is not
|
color is different to default background color, even if component is not
|
||||||
opaque (which is the default). This paints selection if using the component as
|
opaque (which is the default). This paints selection if using the component as
|
||||||
cell renderer a Table, Tree or List.
|
cell renderer in Table, Tree or List.
|
||||||
- TextComponents: Border of focused non-editable text components had wrong
|
- TextComponents: Border of focused non-editable text components had wrong
|
||||||
color.
|
color.
|
||||||
- Custom window decorations: Fixed top window border in dark themes when running
|
- Custom window decorations: Fixed top window border in dark themes when running
|
||||||
|
|||||||
@@ -18,11 +18,14 @@ package com.formdev.flatlaf.ui;
|
|||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Container;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
import java.util.Objects;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
|
import javax.swing.CellRendererPane;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.LookAndFeel;
|
import javax.swing.LookAndFeel;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
@@ -120,10 +123,11 @@ public class FlatRadioButtonUI
|
|||||||
public void paint( Graphics g, JComponent c ) {
|
public void paint( Graphics g, JComponent c ) {
|
||||||
// fill background even if not opaque if
|
// fill background even if not opaque if
|
||||||
// - contentAreaFilled is true and
|
// - contentAreaFilled is true and
|
||||||
// - if background was explicitly set to a non-UIResource color
|
// - if background color is different to default background color
|
||||||
|
// (this paints selection if using the component as cell renderer)
|
||||||
if( !c.isOpaque() &&
|
if( !c.isOpaque() &&
|
||||||
((AbstractButton)c).isContentAreaFilled() &&
|
((AbstractButton)c).isContentAreaFilled() &&
|
||||||
!defaultBackground.equals( c.getBackground() ) )
|
!Objects.equals( c.getBackground(), getDefaultBackground( c ) ) )
|
||||||
{
|
{
|
||||||
g.setColor( c.getBackground() );
|
g.setColor( c.getBackground() );
|
||||||
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
|
g.fillRect( 0, 0, c.getWidth(), c.getHeight() );
|
||||||
@@ -160,6 +164,18 @@ public class FlatRadioButtonUI
|
|||||||
FlatButtonUI.paintText( g, b, textRect, text, b.isEnabled() ? b.getForeground() : disabledText );
|
FlatButtonUI.paintText( g, b, textRect, text, b.isEnabled() ? b.getForeground() : disabledText );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the default background color of the component.
|
||||||
|
* If the component is used as cell renderer (e.g. in JTable),
|
||||||
|
* then the background color of the renderer container is returned.
|
||||||
|
*/
|
||||||
|
private Color getDefaultBackground( JComponent c ) {
|
||||||
|
Container parent = c.getParent();
|
||||||
|
return (parent instanceof CellRendererPane && parent.getParent() != null)
|
||||||
|
? parent.getParent().getBackground()
|
||||||
|
: defaultBackground;
|
||||||
|
}
|
||||||
|
|
||||||
private int getIconFocusWidth( JComponent c ) {
|
private int getIconFocusWidth( JComponent c ) {
|
||||||
AbstractButton b = (AbstractButton) c;
|
AbstractButton b = (AbstractButton) c;
|
||||||
return (b.getIcon() == null && getDefaultIcon() instanceof FlatCheckBoxIcon)
|
return (b.getIcon() == null && getDefaultIcon() instanceof FlatCheckBoxIcon)
|
||||||
|
|||||||
Reference in New Issue
Block a user