My repaint() function doesn't repaint the panel until I drag the window to my second monitor anyone know how can I make it repaint immediately?
Here's my code:
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}
private void doDrawing(Graphics g) {
g.setColor(Color.black);
g.fillRect(0, 0, 927, 900);
g.setColor(Color.white);
//things that aren't getting redrawn
maze.drawEntities(g);
}
@Override
public void run() {
while(true) {
repaint();
try {
Thread.sleep(100);
} catch(Exception e) {
e.printStackTrace();
}
}
}
You almost certainly haven't validated the layout. If you've added or removed components you'll need to do that. revalidate
will validate after you've finished handling the current event, and handily just do it once no matter how many times you call it (during a single event).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.