Results 1 to 7 of 7
  1. #1
    kjiu is offline Member
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Default Problem with "Open"

    Hello,

    I have a problem which is this:

    Java Code:
    JMenuItem openItem = new JMenuItem("Open"); 
          openItem.addActionListener(new ActionListener() 
             { 
                public void actionPerformed(ActionEvent event) 
                { 
                    JFileChooser fileopen = new JFileChooser(); 
                    FileFilter filter = new FileNameExtensionFilter("txt files", "txt"); 
                    fileopen.addChoosableFileFilter(filter); 
    
                    int ret = fileopen.showDialog(null, "Open file"); 
    
                    if (ret == JFileChooser.APPROVE_OPTION) 
                    { 
                      File file = fileopen.getSelectedFile(); 
                    } 
                } 
             } 
          ); 
          fileMenu.add(openItem);

    Is just open but it doesn't appear in the window? Why ?
    Last edited by kjiu; 10-15-2009 at 08:55 PM.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    What doesn't appear in the window?

  3. #3
    kjiu is offline Member
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Default

    I think that there:

    Java Code:
    File file = fileopen.getSelectedFile();
    is the problem...


    // edit: I just what do the File Choosers ... Can you help me ?
    Last edited by kjiu; 10-16-2009 at 08:06 AM.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    I think you need to answer my question.

  5. #5
    kjiu is offline Member
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

    Default

    the file which I choose

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    That's easy then.

    The reason why the file doesn't appear in the window is because you didn't write any code to make it appear in the window at all. A FileChooser does exactly what its name says. It helps you to choose a file. Nothing more.
    Read the API specs for the Desktop.getDesktop().open() method to find out how to open the file using an associated program.

    If you want to display the contents of the file in a JComponent then you need to first decide which type of files can be displayed. Then you would write code to read the file and write its contents to a JComponent.
    Last edited by r035198x; 10-16-2009 at 01:40 PM.

  7. #7
    kjiu is offline Member
    Join Date
    Oct 2009
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Hwlp with "Open", "Save", "Save as..."
    By trill in forum New To Java
    Replies: 3
    Last Post: 11-02-2010, 09:26 AM
  2. Replies: 2
    Last Post: 10-08-2009, 11:28 PM
  3. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  4. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  5. Open "Save Page As" Dialog Box
    By Anubha in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-12-2007, 09:27 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
  •