Nothing in my JFrame appears

只谈情不闲聊 提交于 2019-11-29 17:31:02

Add the components to the content pane :)

Here is a suggestion using the versatile MigLayout:

JPane panel = (JPanel) frame.getContentPane();
panel.setLayout(new MigLayout("fill, wrap 2", "[right][fill]"));

panel.add(lengthL);
panel.add(new JTextField());
panel.add(widthL);
panel.add(new JTextField());
panel.add(areaL);
panel.add(new JTextField());
panel.add(perimeterL);
panel.add(new JTextField());

Simple: Don't call setVisible(true) on the JFrame before adding components to it. Call this only after the whole thing has been set up, at least initially.

You should add the components tpo the JFrame by using the following code:

frame.getContentPane().add(lengthL);
frame.getContentPane().add(widthL);
frame.getContentPane().add(areaL);
frame.getContentPane().add(perimeterL);

you need add Jlabels in frame like under given.

frame.add(lengthL);
frame.add(widthL);
frame.add(areaL);
frame.add(perimeterL);

this only add labels you created if you want another component then create and add it to frame.ex text field.

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