// Create a JTable instance JTable table = new JTable(); // Add data to the table model DefaultTableModel model = (DefaultTableModel) table.getModel(); model.addRow(new Object[] { "John", "Doe", 30 }); // Repaint the table after adding data table.repaint();
// Get the cell data to be changed int row = 0; int col = 1; Object newValue = "Smith"; // Change the cell data table.getModel().setValueAt(newValue, row, col); // Repaint the table after changing cell data table.repaint();These code examples are part of the Java Swing library, which is a part of the Java Platform Standard Edition (Java SE) development kit. Specifically, the components and functionalities are provided by the javax.swing package.