java-org.hwo.ui/src/org/hwo/ui/JBackgroundPane.java

65 lines
1.2 KiB
Java

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