我有一个小程序,设置了它的背景图片,运行良好。
现在我想为JSlider
设置一个背景图片。
我该怎么做呢?
public class CustomSlider extends JSlider
{
private Image img = null;
public CustomSlider()
{
try
{
img = ImageIO.read(new File("background.jpg"));
}
catch (IOException e)
{
e.printStackTrace();
}
}
@Override
public void paintComponent(Graphics g)
{
// Draw the previously loaded image to Component
g.drawImage(img, 0, 0, null);
super.paintComponent(g);
}
}