Reputation: 205
Please help me to add Swing Components like JTable
to already created JFrame
Form using Netbeans
Upvotes: 0
Views: 164
Reputation: 302
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.
Upvotes: 1