Adding JPanel to JFrame

后端 未结 5 1611
长情又很酷
长情又很酷 2021-02-06 04:24

I have a program in which a JPanel is added to a JFrame:

public class Test{

    Test2 test = new Test2();
    JFrame frame = new JFrame();

    Test(){

    ...         


        
5条回答
  •  生来不讨喜
    2021-02-06 04:32

    Test2 test = new Test2();
    ...
    frame.add(test, BorderLayout.CENTER);
    

    Are you sure of this? test is NOT a component! To do what you're trying to do you should let Test2 extend JPanel !

提交回复
热议问题