javax.swing.table


1. Creating a Simple JTable:

import javax.swing.table.*;
import javax.swing.*;

public class SimpleTable {
    public static void main(String[] args) {
        String[] columnNames = {"Name", "Age", "Occupation"};
        Object[][] data = {
            {"John", 25, "Software Engineer"},
            {"Mary", 30, "Doctor"},
            {"Bob", 28, "Teacher"}
        };

        DefaultTableModel model = new DefaultTableModel(data, columnNames);
        JTable table = new JTable(model);

        JFrame frame = new JFrame("Simple Table");
        frame.add(new JScrollPane(table));
        frame.setSize(400, 300);
        frame.setVisible(true);
    }
}

2. Using a Rendered for Cell Values:

3. Using an Editor for Cell Values:

4. Adding a Row to a JTable:

5. Removing a Row from a JTable:

6. Sorting a JTable:

7. Filtering a JTable:

8. Using a Selection Listener:

9. Using a Cell Editor: