From 8cd97556166dba076fc44e71198255268f77fe51 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sat, 28 Jul 2018 14:30:36 -0400 Subject: [PATCH] Update GradientPanel's opaque properly. --- .../masterpassword/gui/util/Components.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java index 3bd1a4c7..e5136125 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/Components.java @@ -441,7 +441,7 @@ public abstract class Components { public GradientPanel(@Nullable final LayoutManager layout, @Nullable final Color gradientColor) { super( layout ); - this.gradientColor = gradientColor; + setGradientColor( gradientColor ); setBackground( null ); setAlignmentX( LEFT_ALIGNMENT ); } @@ -453,17 +453,32 @@ public abstract class Components { public void setGradientColor(@Nullable final Color gradientColor) { this.gradientColor = gradientColor; - revalidate(); + updatePaint(); } @Override - public void doLayout() { - super.doLayout(); + public void setBackground(@Nullable final Color bg) { + super.setBackground( bg ); + updatePaint(); + } - if (gradientColor != null) { - paint = new GradientPaint( new Point( 0, 0 ), gradientColor, new Point( getWidth(), getHeight() ), gradientColor.darker() ); - repaint(); + @Override + public void setBounds(final int x, final int y, final int width, final int height) { + 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