import javax.swing.*; import javax.swing.table.DefaultTableModel; public class TableExample { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame("Table Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a table model with data and column names String[] columnNames = {"Name", "Age", "City"}; Object[][] data = { {"John", 25, "New York"}, {"Alice", 30, "Los Angeles"}, {"Bob", 22, "Chicago"} }; DefaultTableModel model = new DefaultTableModel(data, columnNames); // Create the table using the model JTable table = new JTable(model); // Add the table to a scroll pane to handle scrolling JScrollPane scrollPane = new JScrollPane(table); // Add the scroll pane to the frame frame.getContentPane().add(scrollPane); frame.pack(); frame.setVisible(true); }); } }import javax.swing.*; import javax.swing.table.DefaultTableModel; public class TableExample { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame("Table Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a table model with data and column names String[] columnNames = {"Name", "Age", "City"}; Object[][] data = { {"John", 25, "New York"}, {"Alice", 30, "Los Angeles"}, {"Bob", 22, "Chicago"} }; DefaultTableModel model = new DefaultTableModel(data, columnNames); // Create the table using the model JTable table = new JTable(model); // Add the table to a scroll pane to handle scrolling JScrollPane scrollPane = new JScrollPane(table); // Add the scroll pane to the frame frame.getContentPane().add(scrollPane); frame.pack(); frame.setVisible(true); }); } }