B4J Question DirectoryChooser - show Files?

Patent

Member
Licensed User
Longtime User
Hi community.

I want to choose a Directory with the build in DirectoryChooser.
So far so good.
Problem or wish is:
In this "Dialog" i want to see also the files, so i can decide which Directory i will select!!
Like with the Filechooser, but there i cant choose a Directory.

Is this not possible, or do i miss something?

greets
patent
 

Patent

Member
Licensed User
Longtime User
thanks erel for your hint.
thats not exactly what i want, so i tried it with the swing filechooser.
works roughly perfect, but one thing:
as it should, it is a "modal" dialog.
but because of no fx, it "blocks" the main thread. this has no negative effect, but the mainform becomes white with -no response- while the dialog is open.
its more an optical drawback. no cpu load.
is there a possibility to avoid this?

greets

B4X:
Dim jframe As JavaObject
    jframe.Initializenewinstance("javax.swing.JFrame",Null)       
    jframe.RunMethod("setSize",Array(600,600))
    jframe.RunMethod("setAlwaysOnTop",Array(True))
       
    Dim jfilechooser As JavaObject
    jfilechooser.Initializenewinstance("javax.swing.JFileChooser",Null)
    jfilechooser.RunMethod("setFileSelectionMode",Array(2))        'be able to select files or directories
    jfilechooser.RunMethod("showDialog",Array(jframe,"Select")) 
    Log(jfilechooser.RunMethod("getSelectedFile",Null))            'null or fullpath
 
Upvote 0

Patent

Member
Licensed User
Longtime User
all in all i want to choose a directory.
when this dir is empty i cant choose it with filechooser and its not the best thing to tell the user "choose a file to select the directory".
directorychooser should be ok, but i want to see the files in the directories.
the option to do this was just available in the old swing-chooser :(
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Hi Patent,

Maybe you can still use the following code which works for me. It is based on the FileChosen and a comment from Erel; which I found on one of the questions on the forum. The global variable DirPath function is to bring the user back to his previous directory choice.
B4X:
Dim FileChosen As String
FileChosen = fc.ShowOpen(Mainform)
   
'   We can use the FileChooser and get the folder from the selected file, with File.GetFileParent.
Filename1 = FileChosen.Trim
   
'   Divide directory and filename
DirPath = File.GetFileParent(Filename1)
Filename1 = Filename1.Replace(DirPath, "")
 
Upvote 0

Patent

Member
Licensed User
Longtime User
thank you MicroDrive for your Suggestion.
But the thing was that i want to choose a Directory. see post #5.
greets
 
Upvote 0
Top