title: Open folder containing file and highlight it
body: <p>I'm needing to open a folder containing the specified file, and highlight this said file. I have been looking for this for long but I have been unlucky. Could someone explain how this could be done using java?</p>
  
  <p>Would be much appreciated. I am able to open files, folders, but not open the containing folder and highlighting a file. Cross platform code would be a plus, or just point me to the direction! Thanks!</p>
  
  <p>@UPDATE:</p>
  
  <p>Basically I'm doing an image sorter. I have a <code>ArrayList</code> containing filenames, e.g. myarraylist.get(0) would return funny_cat.jpg</p>
  
  <p>This can be a handy functionality to have in a program that works with files/folders. It's easy enough to actually open the containing folder using:</p>
  
  <p>I want the user to be able to open the currently selected item in a <code>JList</code> and open the containing folder with the target file selected.</p>
  
  <p>I would post the code but it is too long and most unnecesary for this question, I will however post below how I open an explorer window, for the settings section of program, in order to choose a new directory to use:</p>
  
  <pre><code>public void browseFolder(){
  
       System.out.println("browsing!");
  
          final JFileChooser fc = new JFileChooser();
  
          File dir = new File(core.Loader.path);
  
          fc.setCurrentDirectory(dir);
  
          // Windows and Mac OSX compatibility code
          if (System.getProperty("os.name").startsWith("Mac OS X")) {
  
              fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
          } else {
              fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
          }
  
  
          fc.setApproveButtonText("Choose directory");
          int returnVal = fc.showOpenDialog(fc);
  
              if (returnVal == JFileChooser.APPROVE_OPTION) {
  
  
                  File f = fc.getSelectedFile();
                  // if the user accidently click a file, then select the parent directory.
                  if (!f.isDirectory()) {
                      f = f.getParentFile();
                  }
  
                  // debug
                  System.out.println("Selected directory for import " + f);
  
              }
  }
  </code></pre>
  
  <p>@UPDATE </p>
  
  <p>I have found the solution, will post as answer below.</p>