How to set background image in JSlider?

I have an applet. I set its wallpaper. It works great.
Now I want to set the background image to JSlider .
How can i do this?

+4
source share
1 answer

You will need to create your own JSlider class and override the paintComponent method. Be sure to call setOpaque (false) on the slider object.

 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); } } 
0
source

All Articles