Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do you use JFileChooser?

807599Jan 22 2007 — edited Jan 22 2007
I'm having a tough time trying to figure out how to get my JFrame to launch another JFrame that will contain a JFileChooser.

Here is my method that I thought would do it:
 private void generateChooserFrame() {
        JFileChooser chooser = new JFileChooser();
        
        chooserFrame = new JFrame("Choose a file to convert into an icon");
       
        JPanel p = new JPanel(true);
        p.add(chooser);
        chooserFrame.add(p);
        
        chooser.showDialog(p, "Attach");
        
        
        chooserFrame.pack();
        chooserFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        chooserFrame.setVisible(true);
        
        setChooserFrame(chooserFrame);
    }
But when I try this I get

cannot find symbol
symbol: method showDialog(javax.swing.JPanel, java.lang.String)
location: class JFileChooser

I based this on tutorial info I read in the Java API and at http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html to no avail.

What am I doing wrong this time, or am I just too stupid to ever know what I did wrong?

Phil
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 19 2007
Added on Jan 22 2007
19 comments
986 views