JPanel not showing up

后端 未结 3 1535
有刺的猬
有刺的猬 2021-01-27 05:40

Why is the UI not showing up in my code below:

public class GUI extends JPanel{

        public GUI(String name, String address, List reviews, Icon         


        
相关标签:
3条回答
  • 2021-01-27 06:20

    Panels just don't show up in Swing. They have to be added to windows. Create JFrame or JDialog and add your panel to it.

    0 讨论(0)
  • 2021-01-27 06:34

    I guess JPanel cannot be a toplevel container. It has to be put inside a JFrame or JWindow to be shown

    JFrame f=new JFrame();
    f.add(test);
    f.setVisible(true);
    
    0 讨论(0)
  • 2021-01-27 06:43

    A JPanel isn't a top level container. You need to place that JPanel in a JDialog or JFrame. Make sure to add it to the content pane of that dialog or frame:

    JFrame f = new JFrame();
    f.getContentPane().add(test);
    
    0 讨论(0)
提交回复
热议问题