I can't able to insert multiple rows in JTable in netBeans. so please help me.
ThankYou..
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amira BedhiafiRank #601 · 4K reputationPosted Mar 22, 2025, 11:18 AM EDT
Here are the main steps you can follow :
Create a
JTableand aDefaultTableModel.Add columns to the
DefaultTableModel.Insert rows into the
DefaultTableModel.import javax.swing.*; import javax.swing.table.DefaultTableModel; public class JTableExample { public static void main(String[] args) { // Create a JFrame JFrame frame = new JFrame("JTable Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 300); // Create a DefaultTableModel DefaultTableModel model = new DefaultTableModel(); // Add columns to the model model.addColumn("ID"); model.addColumn("Name"); model.addColumn("Age"); // Create a JTable with the model JTable table = new JTable(model); // Add the table to a JScrollPane JScrollPane scrollPane = new JScrollPane(table); // Add the JScrollPane to the frame frame.add(scrollPane); // Insert multiple rows into the table Object[] row1 = {1, "Shubham Wadhwa", 25}; Object[] row2 = {2, "John Doe", 30}; Object[] row3 = {3, "Jane Doe", 28}; model.addRow(row1); model.addRow(row2); model.addRow(row3); // Display the frame frame.setVisible(true); } }