JPanel not showing up

ぃ、小莉子 提交于 2019-12-02 10:06:25
vinothkr

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);

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.

MeBigFatGuy

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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!