Open Dialog is worthless


    Feb 27 2008 | 3:37 am
    The included code for bringing up a file chooser appears to crash max unless housed in a ...
    new Runnable(){put my stuff here}
    ...type of deally. Unfortunately it seems that if you house it in a runnable, anything it reads (that is the point of a file chooser) can't be shared with the rest of the program since it's on a different thread.
    Has anyone else successfully read a file selected by a filechooser into their mxj?
    String initialPath = "."; String selectedPathname = null; JFileChooser openDialog = new JFileChooser(); openDialog.setSelectedFile( new File(initialPath) ); int openResult = openDialog.showOpenDialog(null);
    if(openResult == JFileChooser.APPROVE_OPTION) { selectedPathname = openDialog.getSelectedFile().getPath(); System.out.println(selectedPathname); }

    • Feb 27 2008 | 3:52 am
      Hey Matthew --
      I ran into the same difficulty, but then I noticed that various filedialogs are included as part of the MaxSystem class (maybe the Runnable() scoping is why).
      This code sets up a [loadbuf] message, with or without an additional filename as part of the message. It reads the file into an internal buffer "lispbuf":
      String lispfname;
      public void loadbuf(String lf) { if (lf.length() == 0) lispfname = MaxSystem.openDialog(); else lispfname = lf;
      if (lispfname != null) { try { File ff = new File(lispfname); FileReader fr = new FileReader(ff); char [] cbuf = new char[(int)ff.length()]; fr.read(cbuf); lispbuf = new String(cbuf); } catch (IOException o) { error("could not load file: " + lispfname); } } }
      hope this helps!
      brad
      On Feb 26, 2008, at 10:37 PM, Matthew Aidekman wrote:
      > > The included code for bringing up a file chooser appears to crash > max unless housed in a ... > > new Runnable(){but my stuff here} > > ...type of deally. Unfortunately it seems that if you house it in > a runnable, anything it reads (that is the point of a file chooser) > can't be shared with the rest of the program since it's on a > different thread. > > Has anyone else successfully read a file selected by a filechooser > into their mxj? > > > > > > String initialPath = "."; > String selectedPathname = null; > JFileChooser openDialog = new JFileChooser(); > openDialog.setSelectedFile( new File(initialPath) ); > int openResult = openDialog.showOpenDialog(null); > > if(openResult == JFileChooser.APPROVE_OPTION) > { > selectedPathname = openDialog.getSelectedFile().getPath(); > System.out.println(selectedPathname); > }
    • Feb 27 2008 | 4:49 am
      YOU My friend Just made my day!
    • Feb 28 2008 | 8:59 am
      i seem to remember java.awt.Dialog being better behaved than JDialog within max. t
      On Feb 26, 2008, at 19:37 PM, Matthew Aidekman wrote:
      > > The included code for bringing up a file chooser appears to crash > max unless housed in a ... > > new Runnable(){but my stuff here} > > ...type of deally. Unfortunately it seems that if you house it in > a runnable, anything it reads (that is the point of a file chooser) > can't be shared with the rest of the program since it's on a > different thread. > > Has anyone else successfully read a file selected by a filechooser > into their mxj? > > > > > > String initialPath = "."; > String selectedPathname = null; > JFileChooser openDialog = new JFileChooser(); > openDialog.setSelectedFile( new File(initialPath) ); > int openResult = openDialog.showOpenDialog(null); > > if(openResult == JFileChooser.APPROVE_OPTION) > { > selectedPathname = openDialog.getSelectedFile().getPath(); > System.out.println(selectedPathname); > }