title: getting data out of selection listener java
body: <p>I am building a Graphical User Interface, and used a <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html" rel="nofollow">FileChooser</a> to pick up the file the user choose, so everything works fine, but now i am trying to get the path of the file selected (made quite easily through a <code>file.getAbsolutePath()</code>).</p>
  
  <p>But somehow i can't get it out of the class... i want to have a String path in the class with the listener, which looks like this :</p>
  
  <pre><code>private void browseButton(Canvas BasicSelection)
  {
      final Button btnBrowse = new Button(BasicSelection, SWT.NONE);
      btnBrowse.setBounds(70, 29, 68, 23);
      btnBrowse.setText("Browse");
      btnBrowse.addSelectionListener(new SelectionAdapter() 
      {
          public void widgetSelected(SelectionEvent arg0) 
          {
              filechooser.createAndShowGUI(path);
              sbtnBrowse = btnBrowse.getSelection();
          }
      });
      launchEvent();
  }
  </code></pre>
  
  <p>And here is the action performed when the button is clicked : </p>
  
  <pre><code>public void actionPerformed(ActionEvent e) 
  {
      //Set up the file chooser.
      if (fc == null)
      {
          fc = new JFileChooser();
      }
      fc.addChoosableFileFilter(new Filter());
      fc.setAcceptAllFileFilterUsed(false);
  
      //Show it.
      int returnVal = fc.showDialog(FileChooser.this,"Attach");
  
      //Process the results.
      if (returnVal == JFileChooser.APPROVE_OPTION) 
      {
          File file = fc.getSelectedFile();
          setPath(file);
          log.append("Attaching file: " + file.getName() + "." + newline);
          // Here is where i would need to get the file... but how ?
      } 
      else 
      {
          log.append("Attachment cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());
  
      //Reset the file chooser for the next time it's shown.
      fc.setSelectedFile(null);
  }
  </code></pre>
  
  <p>How can i get the file name out of the class ?</p>
  
  <p>EDIT : I already tried with getters and setters but strangely he tried to access the content before i actuallt wrote in it.</p>
  
  <pre><code>String path ;
  /*
   Rest of the code ...
  */
  public void setPath(File input)
  {
      if (input != null)
      {
          this.path = input.getAbsolutePath();
          System.out.println("path is now set correctly : ");
      }
  }
  public String getPath()
  {
      return this.path;
  }
  </code></pre>