How to replace JPanel with another JPanel

前端 未结 6 1685
有刺的猬
有刺的猬 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:27

    Try this, Following code will load the second jPanel (NewOrder) to first jPanel(jpMain)

    NewOrder no = new NewOrder(); //This is the object of Second JPanel
    
    // jpMain - This is the First JPanel
    jpMain.setLayout(new java.awt.BorderLayout());
    jpMain.removeAll();
    jpMain.add(no);
    jpMain.revalidate();
    

提交回复
热议问题