From d0b131b3d8d6fab596af97c85f3fdc72e950bad1 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Thu, 24 Jul 2014 20:37:58 +0200 Subject: [PATCH] New: JBackgroundPane --- src/org/hwo/ui/JBackgroundPane.java | 64 +++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/org/hwo/ui/JBackgroundPane.java diff --git a/src/org/hwo/ui/JBackgroundPane.java b/src/org/hwo/ui/JBackgroundPane.java new file mode 100644 index 0000000..47fdff4 --- /dev/null +++ b/src/org/hwo/ui/JBackgroundPane.java @@ -0,0 +1,64 @@ +package org.hwo.ui; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Image; +import java.util.prefs.BackingStoreException; + +import javax.swing.JComponent; +import javax.swing.JPanel; + +public class JBackgroundPane extends JPanel { + + private Image backgroundImage; + private boolean scaleBackground; + + public JBackgroundPane() + { + + } + + @Override + protected void paintComponent(Graphics arg0) { + super.paintComponent(arg0); + if (backgroundImage != null) + { + int w,h; + if (scaleBackground) + { + w = getWidth(); + h = getHeight(); + } else + { + w = backgroundImage.getWidth(null); + h = backgroundImage.getHeight(null); + } + arg0.drawImage(backgroundImage, 0, 0, w, h, null); + } + } + + + + public Image getBackgroundImage() { + return backgroundImage; + } + + + + public void setBackgroundImage(Image backgroundImage) { + this.backgroundImage = backgroundImage; + + Dimension pSize = new Dimension(backgroundImage.getWidth(null), backgroundImage.getHeight(null) ); + this.setPreferredSize(pSize); + } + + public boolean isScaleBackground() { + return scaleBackground; + } + + public void setScaleBackground(boolean scaleBackground) { + this.scaleBackground = scaleBackground; + } + +}