0

Having read here and not understood the concept, I had to post my issue here. I am trying take the input value from Keyword JTextField and filter my JTable table_job. enter image description here

When search button is pressed, it should change the table in Job List panel to only display the set of jobs which includes the keyword in any of the column in its table. Currently, I am having no luck and am getting blank screens.

Here is the Job List Screen

enter image description here

The table on right does not update according to keyword.

Here is what I tried and failed, I am new to table filtering.

try {              
    jobTableInit(); 
    String value = keyword.getText();

    TableRowSorter sorter;
    sorter = new TableRowSorter<DefaultTableModel>(new DefaultTableModel());
    RowFilter<DefaultTableModel, Object> rowFilter = null;
    try {
       rowFilter = RowFilter.regexFilter(keyword.getText());
    }
    catch(java.util.regex.PatternSyntaxException ex) {
       return;
    }
    sorter.setRowFilter(rowFilter);
    table_job.setRowSorter(sorter);
 }            
 catch (Exception e) {
    JOptionPane.showMessageDialog(null, e);
 }                                

Can somebody suggest recommendations or show me a simple example code?

Till Helge
  • 9,253
  • 2
  • 40
  • 56
Hoody
  • 2,942
  • 5
  • 28
  • 32
  • For better help sooner, post an [SSCCE](http://sscce.org/). And **use a consistent and logical indent for code blocks.** The indentation of the code is intended to help people understand the program flow. – Andrew Thompson Jan 12 '13 at 12:50
  • *"display jobs which include the matching term"* See [How to use Tables - Sorting and Filtering](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting). – Andrew Thompson Jan 12 '13 at 12:53

1 Answers1

2

by default there are two ways

  1. use custom Comparator and search in the XxxTableModel (or JTables view by using Pattern), more about Comparator is described in JTables tutorial about Sorting and Filtering

  2. use built_in RowFilter in TableRowSorter, then filtered JTables view returns desired List_of_Xxx

  3. another idea is only to hightlighting matches

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • there is possible to search from both JTextFields, apply RowFilter to concrete TableColumn,nnot whole JTable, only one column, I can't see any issue, – mKorbel Jan 12 '13 at 15:21