How to stop the auto-repaint() when I resize the Jframe

前端 未结 2 1684
日久生厌
日久生厌 2021-01-24 21:16

I am still learning Java, if someone can help me I will be very happy!

Sorry for bad english, I am spanish! I am making a tile game, the game uses the classic \"game loo

2条回答
  •  既然无缘
    2021-01-24 21:24

    so when the JFrame isn't maximized

    I don't know why this would cause a problem since only one repaint request should be generated.

    or (resizing)

    I can see this being a problem since repaint will be invoked for every pixel you resize the frame by. In this case maybe you can use:

    Toolkit.getDefaultToolkit().setDynamicLayout(false); 
    

    Now the components will validated after resizing is complete.

    this.setBackground(new Color(210,247,255));

    Don't use code like the above since changing the background causes repaint() to be invoked which will invoke the paintComponent() method again. Painting methods are for painting only.

提交回复
热议问题