Results 1 to 2 of 2
  1. #1
    Cateander is offline Member
    Join Date
    Mar 2014
    Posts
    1
    Rep Power
    0

    Default JOptionPane and JFileChooser not showing up

    I have been programming in java for a bit now and can generally figure out things. But this one has me stumped. I have a mac and I have recently updated from java 6 to java 7. I had quite a bit of code that was running fine with java 6, but is having problems in java 7. The precise problem is that only the first JFileChooser dialog window in the program will actually show up (the window to select the files). I include a snippet of code below:

    JFileChooser chooser1 = new JFileChooser();
    chooser1.setDialogTitle("get one file");
    int returnVal = chooser1.showOpenDialog(null);
    if(returnVal == JFileChooser.APPROVE_OPTION)
    System.out.print("FileNAme 1:"+chooser1.getSelectedFile().getName());

    JFileChooser chooser2 = new JFileChooser();
    chooser2.setDialogTitle("get another file");
    returnVal = chooser2.showOpenDialog(null);
    if(returnVal == JFileChooser.APPROVE_OPTION)
    System.out.print("FileNAme 1:"+chooser2.getSelectedFile().getName());

    Only the open dialog window of chooser1 will show up. The dialog window for chooser2 never shows up. The program acts like the chooser2.show OpenDialog statement is executing and is waiting for me to select a file, but nothing shows up.

    As I said code like this (several JOptionChooser dialogs or JOptionPane dialog in a row) ran with no problem before the upgrade to java 7. Now only the first one show up. ?????? help!

  2. #2
    djmordigal is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Re: JOptionPane and JFileChooser not showing up

    You should be able to just use the same JFileChooser object as many times as you need to prompt for files.

    Java Code:
    public class JFileChooserDemo {
        public static void main(String[] args) {
            JFileChooser jfc = new JFileChooser();
            int returnVal = jfc.showOpenDialog(null);
            if(returnVal == jfc.APPROVE_OPTION) {
                System.out.println("File 1: " + jfc.getSelectedFile().getName());
            }
            returnVal = jfc.showOpenDialog(null);
            if(returnVal == jfc.APPROVE_OPTION) {
                System.out.println("File 2: " + jfc.getSelectedFile().getName());
            }
        }
    }
    And so on...

Similar Threads

  1. Replies: 38
    Last Post: 10-09-2012, 08:04 PM
  2. JFileChooser
    By snus in forum Java Applets
    Replies: 11
    Last Post: 12-25-2010, 07:46 PM
  3. jFileChooser
    By ArneBassez in forum AWT / Swing
    Replies: 7
    Last Post: 12-01-2010, 04:38 AM
  4. JfileChooser Help
    By simmi in forum AWT / Swing
    Replies: 9
    Last Post: 08-04-2009, 02:24 AM
  5. Need JFileChooser Help
    By Wraithier in forum New To Java
    Replies: 4
    Last Post: 06-18-2008, 05:40 PM

Tags for this Thread

Posting Permissions

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