How to replace JPanel with another JPanel

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

    you need to do like this :

         public void actionPerformed(ActionEvent e) {
            //System.out.println("in");
            contain = getContentPane();
            contain.removeAll();
            //System.out.println("in2");
    
            reChange2 = new JPanel(null);
            reChange2.setBackground(Color.white);
            reChange2.setSize(240, 225);
            reChange2.setBounds(50, 50, 240, 225);
            //System.out.println("in3");
    
            contain.add(reChange2);
            validate();
            repaint();
            //System.out.println("in4");
            setVisible(true);
            //System.out.println("in5");
        }
    });
    

提交回复
热议问题