Loading Transparency in Image
I have a JSlider and I want an image to mark the center of the slider. This image has a transparent background:
JSlider j =new JSlider();
staticfinalint BARHEIGHT = 15;
staticfinalint BARYPOS = 15;
public BreakEvenSliderUI(JSlider js)
{
super(js);
j = js;
}
publicvoid paintTrack(Graphics g)
{
g.setColor(new Color(0.5f,0.0f,0.0f,0.3f));
g.fill3DRect(0,BARYPOS,
xPositionForValue(j.getValue()),
BARHEIGHT,true);
g.setColor(new Color(0.0f,0.0f,0.5f,0.3f));
g.fill3DRect(xPositionForValue(j.getValue()),BARYPOS,
j.getWidth() - xPositionForValue(j.getValue()),
BARHEIGHT,true);
File f =new File("images/logo.png");
try
{
BufferedImage image = ImageIO.read(f);
Image beCenter = image;
int xCenterOfTrack = (int)((j.getBounds().getWidth()) / 2);
g.drawImage(beCenter,
xCenterOfTrack - 25,
BARYPOS - 15,
j.getBackground(),
j);
}
catch(IOException ex){}
}
Graphics.drawImage() is painting the transparent part of the image to the background color. However, is there a way to have it paint what is behind the image and not just the background?

