Setting Filters

Report a typo

What code should be added below to filter the table for values which are equal to Bob

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);

    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
    table.setRowSorter(sorter);
    sorter.setRowFilter(__________________);

}
Enter a short text
___

Create a free account to access the full topic