title: Search text file and display results in a JPanel
body: <p>Does anyone have any ideas on how I can search a text file and list the results in a JComponent, like a JPanel.</p>
  
  <p>I've been trying to make this work out for two days now, but no success will really appreciate a reply. Thanks a lot in advance.</p>
  
  <p>I've been trying to write a class that handles search queries to a text file. My main goal is to get the lines in a text file that contain the search keywords entered in a JTextField and print them out in an appropriate JComponent(something like a JTextField, JTextPane, whichever best applicable). </p>
  
  <p>I'd like the search results to show in columns like how google search results get displayed, so that each line from the text file gets printed in its own line. I've been told that it's best to use an ArrayList. I really don't know how to do this. I've picked up ideas from all over and this is what I have so far:</p>
  
  <p>Much appreciation in advance. I am very new to Java. I've been at it the whole day trying to get this right and have not gone any far. Am willing to try anything offered, even a new approach.</p>
  
  <pre><code>// The class that handles the search query
  // Notice that I've commented out some parts that show errors
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  import javax.swing.JTextPane;
  
  
  public class Search {
  
      public static String path;
      public static String qri;
  
      public Search(String dTestFileDAT, String qry) {
          path = dTestFileDAT;
          qri = qry;
      }
  
      public static JTextPane resultJTextPane;
      public static List&lt;String&gt; linesToPresent = new ArrayList&lt;String&gt;();
  
      public static List&lt;String&gt; searchFile(String path, String match){
  
          File f = new File(path);
          FileReader fr;
          try {
              fr = new FileReader(f);
              BufferedReader br = new BufferedReader(fr);
              String line;
                  do{
                      line = br.readLine();
                      Pattern p = Pattern.compile(match);
                      Matcher m = p.matcher(line);
                      if(m.find())
                          linesToPresent.add(line);
                  } while(line != null);
  
                  br.close();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          // resultJTextPane = new JTextPane();
          // resultJTextPane = (JTextPane) Home.BulletinsJPanel.add(linesToPresent);
  
          return linesToPresent;
      }
  }
  
  // This handles the click event to take the query. Notice that I've commented out some parts that show errors
  private void mouseClickedSearch(java.awt.event.MouseEvent evt) {
      Search fs = new Search("/D:/TestFile.dat/", "Text to search for");
  
      // searchResultsJPanel.add(Search.searchFile("/D:/TestFile.dat/", "COLE"));
      // searchResultsJTextField.add(fs);
  }
  </code></pre>