[java-dev] Open Dialog is worthless
Brad Garton
garton at columbia.edu
Tue Feb 26 20:52:06 MST 2008
- Previous message: [java-dev] Open Dialog is worthless
- Next message: [java-dev] Re: Open Dialog is worthless
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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);
> }
> _______________________________________________
> java-dev mailing list
> java-dev at cycling74.com
> http://www.cycling74.com/mailman/listinfo/java-dev
- Previous message: [java-dev] Open Dialog is worthless
- Next message: [java-dev] Re: Open Dialog is worthless
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
