JPanel doesn't repaint if repaint() is called within JFrame code
问题 I have a class Forest and CellularJPanel , which extends JPanel and displays Forest . I wrote a primitive code to create JFrame , Forest , CellularJPanel and add CellularJPanel to the JFrame . Next is an infinite loop, which makes Forest update and CellularJPanel repaint. JFrame jFrame = new JFrame(); Forest forest = new Forest(); CellularJPanel forestJPanel = new CellularJPanel(forest); jFrame.add(forestJPanel); jFrame.pack(); //jFrame.setResizable(false); jFrame.setLocationRelativeTo(null);