Adding JPanel to JFrame

后端 未结 5 1617
长情又很酷
长情又很酷 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:31

    Your Test2 class is not a Component, it has a Component which is a difference.

    Either you do something like

    frame.add(test.getPanel() );
    

    after you introduced a getter for the panel in your class, or you make sure your Test2 class becomes a Component (e.g. by extending a JPanel)

提交回复
热议问题