New: JBackgroundPane

thobaben_serialize
Harald Wolff 2014-07-24 20:37:58 +02:00
parent 23dec63158
commit d0b131b3d8
1 changed files with 64 additions and 0 deletions

View File

@ -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;
}
}