Hi guys. Ive got a program thats an extension of JFrame and it had a JPanel component that I only want to repaint when I tell it to (for the sake of efficiency).
In my main program have a while(true) loop in which there is a
thread sleeping and calls some functionality:
this is inside a try/catch btw
imagepanel.Set_image(database.get_current_image());
database.Update_image(direction_forward);
// imagepanel.revalidate();
// imagepanel.repaint();
// map_panel.repaint();
repaint();
jTabbedPane1.revalidate();
jTabbedPane1.repaint();
jMenuBar1.revalidate();
jMenuBar1.repaint();
t.sleep(time_interval);
as you can ee Ive tried a few things, but currently my JPanel will update, however it does it constantly.
this is the paintComponent method inside my extended JPanel class, imagepanel.
public void paintComponent(Graphics g) {
System.out.println(image_name);
g.drawImage(img, 0, 0, null);
super.paintComponent(g);
repaint();
}
this method works, however it calls it way too much. What I would like is to be able to call all repaints from my main method by using something like imagepanel.repaint(); and not calling the repaint(); inside imagepanel. If I do that it doesnt work. Nothing gets displayed.
Any thoughts?