2
0

Update GradientPanel's opaque properly.

This commit is contained in:
Maarten Billemont 2018-07-28 14:30:36 -04:00
parent 46d301df94
commit 8cd9755616

View File

@ -441,7 +441,7 @@ public abstract class Components {
public GradientPanel(@Nullable final LayoutManager layout, @Nullable final Color gradientColor) { public GradientPanel(@Nullable final LayoutManager layout, @Nullable final Color gradientColor) {
super( layout ); super( layout );
this.gradientColor = gradientColor; setGradientColor( gradientColor );
setBackground( null ); setBackground( null );
setAlignmentX( LEFT_ALIGNMENT ); setAlignmentX( LEFT_ALIGNMENT );
} }
@ -453,17 +453,32 @@ public abstract class Components {
public void setGradientColor(@Nullable final Color gradientColor) { public void setGradientColor(@Nullable final Color gradientColor) {
this.gradientColor = gradientColor; this.gradientColor = gradientColor;
revalidate(); updatePaint();
} }
@Override @Override
public void doLayout() { public void setBackground(@Nullable final Color bg) {
super.doLayout(); super.setBackground( bg );
updatePaint();
}
if (gradientColor != null) { @Override
paint = new GradientPaint( new Point( 0, 0 ), gradientColor, new Point( getWidth(), getHeight() ), gradientColor.darker() ); public void setBounds(final int x, final int y, final int width, final int height) {
repaint(); super.setBounds( x, y, width, height );
updatePaint();
}
private void updatePaint() {
setOpaque( (getGradientColor() != null) || (getBackground() != null) );
if (gradientColor == null) {
paint = null;
return;
} }
paint = new GradientPaint( new Point( 0, 0 ), gradientColor,
new Point( getWidth(), getHeight() ), gradientColor.darker() );
repaint();
} }
@Override @Override