I've got a window (public class Panel extends JPanel) that is setting its background from URL
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
try
{
this.imgBG = ImageIO.read(new URL("http://myhost.com/bg.png"));
}
catch (Exception e)
{
System.out.println("[ERROR] Could not load custom background image! Using resources.");
this.imgBG = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Resources/bg.png"));
}
g.drawImage(imgBG, 0, 0, this);
}
If it won't load an image, then it will use one from Resources. The problem is those images are heavy in memory and loading them is lagging whole window. Is there a way I can paint BG in background thread? If not, is this a good solution:
- Use LayeredPanel
- Create JLabel with size of window and place it in background
- Make new Runnable thread that will get image and JLabel.setIcon(image)