简体   繁体   English

如何将Swing组件添加到另一个JFrame?

[英]How to add Swing Components to another JFrame?

请帮助我使用Netbeans将Swing组件(如JTable添加到已创建的JFrame Form中

Take a look at this 看看这个

JFrame frame = new JFrame();
frame.setSize(300,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JTable table = new JTable(5, 5);
table.setBackground(Color.GRAY);

frame.setLayout(new FlowLayout());
frame.add(table);

The last two lines are the key in adding a component to a JFrame. 最后两行是将组件添加到JFrame的关键。 You need to set a Layout that the Swing would be following in adding the component to the frame, then add the component. 您需要设置将组件添加到框架中后,Swing将遵循的布局,然后添加组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM