简体   繁体   English

repaint() 在我拖动 window 之前不会重新绘制

[英]repaint() doesn't repaint until I drag the window around

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?我的 repaint() function 不会重新绘制面板,直到我将 window 拖到我的第二台显示器上,有人知道如何让它立即重新绘制吗?

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). revalidate将在您处理完当前事件后进行验证,并且无论您调用多少次(在单个事件期间)都可以轻松地执行一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM