How to replace JPanel with another JPanel

前端 未结 6 1686
有刺的猬
有刺的猬 2021-01-05 10:46

I want to replace a Jpanel with another one in a JFrame I already search and try my code but nothing\'s happen this is my code :

public class Frame extends          


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-05 11:10

    1. don't to use AbsoluteLayout

    2. change validate(); in actionPerformed to contain.validate(); and follows with contain.repaint();

    3. rename class name (reserved Java word, or methods name) Frame (java.awt.Frame) to MyFrame (for example)

    4. use CardLayout instead of remove and then add a new JPanel on runtime

提交回复
热议问题