Results 1 to 3 of 3

Thread: JFileChooser

  1. #1
    Madoka is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default JFileChooser

    Ok, here is a simple example using JFileChooser and for some reason it's saying it can't find the symbol "File" in the line "File chosenFile = fileChooser.getSelectedFile();". I feel liken this is something really simple, that I am forgetting.




    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.Color;

    public class JavaExample
    {
    public static void main (String [] args)
    {
    JFileChooser fileChooser = new JFileChooser();
    int status = fileChooser.showOpenDialog(null);

    if (status == JFileChooser.APPROVE_OPTION)
    {
    File chosenFile = fileChooser.getSelectedFile();
    String fileName = chosenFile.getPath();
    JOptionPane.showMessageDialog(null,"The file's path is : " + fileName);
    }
    else if (status ==JFileChooser.CANCEL_OPTION)
    {
    JOptionPane.showMessageDialog(null,"You chose to cancel.");
    }
    else
    {
    JOptionPane.showMessageDialog(null,"ERROR");
    }
    }
    }

  2. #2
    Madoka is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: JFileChooser

    Forgot to import the java.io.*; package. Haha, I think I'm having an off day. :p

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: JFileChooser

    Where's the import for File? If you don't know what you need to import, look it up in the API.

    And I suggest you get rid of unused imports; they just add clutter and obscure which classes are actually used.

    db

    edit Posts crossed. The suggestion still stands. And why do an import on demand when you only need one class from that package?
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. jfilechooser
    By ranadav in forum AWT / Swing
    Replies: 7
    Last Post: 06-03-2010, 03:44 PM
  2. Jfilechooser
    By greatmajestics in forum Java 2D
    Replies: 5
    Last Post: 03-30-2010, 07:13 PM
  3. help with JFileChooser
    By morgatron in forum New To Java
    Replies: 1
    Last Post: 01-08-2010, 10:00 AM
  4. JfileChooser Help
    By simmi in forum AWT / Swing
    Replies: 9
    Last Post: 08-04-2009, 03:24 AM
  5. how to use JFileChooser
    By tommy in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 09:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •