Intermediate
Date of registration: Jan 1st 2009
Location: Hanover, Germany
Occupation: Software Engineer
Hobbies: Hilbert Curves
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
Public Sub Command1_Click() Dim fileName As String With CommonDialog1 .Filter = "" ' Load filters. AddFilter CommonDialog1, "Text Files", "*.txt" AddFilter CommonDialog1, "Graphic Files", _ "*.bmp;*.gif;*.jpg" AddFilter CommonDialog1, "All Files", "*.*" .ShowOpen True fileName = .FileName End With MsgBox fileName End Sub ' Add a filter to the dialog in an easy way. ' from www.vb-helper.com/howto_add_commondialog_filters.html Private Sub AddFilter(ByVal dlg As CommonDialog, _ ByVal filter_title As String, ByVal filter_value As String) Dim txt As String txt = dlg.Filter If Len(txt) > 0 Then txt = txt & "|" txt = txt & filter_title & " (" & filter_value & ")|" & _ filter_value dlg.Filter = txt End Sub |
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
Private myInitDir As String Private myFilter As String Private myIsCanceled As Boolean Private myFile As File Private myFiles() As File Public Property Get InitDir() As String InitDir = myInitDir End Property Public Property Let InitDir(value As String) myInitDir = value End Property Public Property Get Filter() As String Filter = myFilter End Property Public Property Let Filter(value As String) myFilter = value End Property Public Property Get FileName() As String FileName = myFile.getAbsolutePath End Property Public Property Let FileName(value As String) myFile = New File(value) End Property Public Property Get FileFile() As File FileFile = myFile End Property Public Function getFiles() As File() getFiles = myFiles End Function Public Property Get IsCanceled() As Boolean IsCanceled = myIsCanceled End Property Public Sub ShowOpen() Dim ofd As javax#swing#JFileChooser If Len(myInitDir) > 0 Then ofd = New javax#swing#JFileChooser(myInitDir) Else ofd = New javax#swing#JFileChooser End If If myFile <> Nothing Then ofd.setSelectedFile(myFile) End If If Len(myFilter) > 0 Then Call AddFilters(ofd) End If ofd.showOpenDialog(Nothing) myFile = ofd.getSelectedFile If myFile = Nothing Then myIsCanceled = True Else myFiles = ofd.getSelectedFiles End If End Sub Private Sub AddFilters(fd As javax#swing#JFileChooser) Dim s() As String Dim i As Integer Dim description As String Dim ext As String s() = Split(myFilter, "|") For i = 0 To Ubound(s) Step 2 If (i + 1) <= Ubound(s) Then description = s(i) ext = s(i + 1) If Len(ext) > 0 Then AddFilter(fd, description, ext) End If End If Next End Sub Private Sub AddFilter(fd As javax#swing#JFileChooser, description As String, ext As String) Dim extensions() As String Dim jext As java#lang#String = ext If jext.contains("*.") Then jext = Replace(ext, "*.", "") End If If jext.contains(";") Then extensions = Split(jext, ";") Else ReDim extensions(0) extensions(0) = jext End If fd.addChoosableFileFilter(New javax#swing#filechooser#FileNameExtensionFilter(description, extensions())) End Sub |
yes, the javax#swing#JFileChooser looks very similar to the original CommonDialog-controlQuoted
The two dialogs look the same