title: Java JTable - show rows only which matches the string
body: <p>I have a <code>JTable</code> populated with data from a database. I have added a search function that display the rows, if word matched to some rows when the data is typed into a <code>JTextField</code>. But at the minute as you type a string or word that do not matches any of the rows data, what I want to do is to hide all the rows, and the <code>JTable</code> will show just the column names. Just like when something matches IT, shows those rows only which has the string that user typed and hide others.</p>
  
  <p>Here is my code that I am using:</p>
  
  <pre><code>               if (text.length() == 0) {
                   sorter.setRowFilter(null);
                 } else {
                   try {
                     sorter.setRowFilter(
                         RowFilter.regexFilter(text));
                   } catch (PatternSyntaxException pse) {
                     System.err.println("Bad regex pattern");
                   }
                 }
               }
  </code></pre>