I need to reload the JPanel's background image, when data submitted to Database. I create JPanel that populate image from Database. And when i updated the image, and submit it, the background automatically change. I also try to use repaint() and revalidate() but it wont work. It must to restart application and run again, it works.
This is my code to display background in JPanel.
public void getLogo(Company company, PanelCompany view) {
JPanel panel = new BackgroundImage(company.getLogoBlob());
panel.revalidate();
panel.setVisible(true);
panel.setBounds(10, 10, 120, 120);
view.getPanelPhoto().add(panel);
}
This my helper class :
public class BackgroundImage extends JPanel{
private Image image;
public BackgroundImage (InputStream input) {
try {
image = ImageIO.read(input);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void paintComponent(Graphics grphcs) {
super.paintComponent(grphcs);
Graphics2D gd = (Graphics2D) grphcs.create();
gd.drawImage(image, 0, 0, getWidth(), getHeight(), this);
gd.dispose();
}
}
Any solutions? Thanks for your attention before :)