简体   繁体   中英

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. You need to set a Layout that the Swing would be following in adding the component to the frame, then add the component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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