Posted by
Michael Schmid on
Apr 06, 2015; 10:42am
URL: http://imagej.273.s1.nabble.com/Possible-to-set-default-directory-tp5012356p5012362.html
Hi Jon,
your code is absolutely fine (I guess that you have an 'else' branch for
the case that fi.directory == null).
By the way, OpenDialog.setDefaultDirectory is a static method, so you can
set it without having a particular instance of OpenDialog, just use the
class name as a prefix:
OpenDialog.setDefaultDirectory(myDefaultDirectory);
The String argument (here 'myDefaultDirectory') may have a path separator
(backslash for Windows, otherwise slash) at the end.
You need the static method if the OpenDialog is no called by your code but
rather by some other command, so you have no access to the instance of
OpenDialog.
Michael
________________________________________________________
On Sun, April 5, 2015 22:21, Jon Harman wrote:
> Thanks Michael.
>
> My knowledge of Java is minimal. I don't see how to use
> setDefaultDirectory() without an OpenDialog.
>
> I now do this:
>
> FileInfo fi = imp.getOriginalFileInfo();
> if(fi.directory != null) {
> OpenDialog defdia = new OpenDialog("",fi.directory);
> }
>
> Jon
>
>
> On 4/5/2015 11:52 AM, Michael Schmid wrote:
>> On Sun, April 5, 2015 20:10, Jon Harman wrote:
>>> When my plugin is executed from a command line sometimes the default
>>> directory gets incorrectly set (to c:\windows).
>>> So far I have not not figured out what is going on, but a possible fix
>>> would be to set that default directory to be the directory of the image
>>> opened in my plugin. Any way to do that? I don't see any way in the
>>> ImageJ open code.
>>
>> Hi Jon,
>>
>> ij.io.OpenDialog has a method
>> public OpenDialog(String title, String defaultDir, String
>> defaultName)
>>
>> where you can set the default directory. If you use some other way of
>> opening the file, you can use the OpenDialog method
>> public static void setDefaultDirectory(String defaultDir)
>>
>> to set the default directory.
>>
>> You can get the directory of an image via the ImagePlus method
>> String dir = imp.getOriginalFileInfo().directory;
>> Note that the directory many be null (if the image was not read from
>> disk).
>>
>> Michael
>>
>> --
>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>>
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html