Add Table Listener

Report a typo

Add the correct code to implement table listeners in the class below

public class JTableExample extends JFrame implements ____________ {

    public static void main(String[] args) {
        JTableExample table = new JTableExample();
        table.setVisible(true);
    }

    public JTableExample() {
        super("JTable Example");
        setSize(500, 500);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().setBackground(Color.white);


        TableModel tableModel = new MyTableModel();

        JTable table = new JTable(tableModel);

        table.getModel().addTableModelListener(this); //Adds the TableModelListener
        JScrollPane sp = new JScrollPane(table);
        this.add(sp);

        tableModel.setValueAt("James",0,0);


    }

    @Override
    public void tableChanged(TableModelEvent e) {
        System.out.println("Table Updated!");
    }
}
Enter a short text
___

Create a free account to access the full topic