JFileBrowser methods

 

JFileBrowser methods

createJFileBrowser (

        in String pParentBoxId,

        in String pTitle,

        in String pPathName);

This creates a JFileBrowser which can browse files to be opened or saved.

 

The "pParentBoxId" parameter defines the parent dialog box for which the JFileBrowser is transient.

 

The "pTitle" parameter defines the title of the file browser.

 

The "pPathName" parameter defines the absolute path to the starting point file or directory.

 

public getTitle ()

return String

This returns the title of the dialog box.

 

public setTitle (

        pTitle in String )

This sets the title of the dialog box.  The "pTitle" parameter defines the title.

 

public get ()

return String

This is used to display the file browser as a modal dialog box.  It returns a string expressing the full path name selected, or O is the dialog box was cancelled.  This string must never be deleted or modified.

 

public getDirectory ()

return String

This returns the directory part of the selected path.

 

public setDirectory (

        pDirectory in String )

This sets the directory which is to be browsed.  The "pDirectory" parameter defines the directory.

 

public getFileName ()

return String 

This returns the file name part of the selected path.

 

public setFileName (

        pFileName in String )

This sets the default file name.  The "pFileName" parameter defines the file name.

 

public getPathName ()

return String 

This returns the full name of the selected path.

 

public setPathName (

        pPathName in String )

This sets the directory to be browsed and the default file name.  The "pPathName" parameter defines the path name.

 

public getType ()

return JFileBrowserType

This returns the type of the current dialog box.

 

public addFilter (

        pFilter in String,

        pFilterDesc in String )

This adds a file filter and a related message.  The "pFilter" parameter defines the filter.  The "pFilterDesc" parameter defines the message related to the filter.

 

public resetFilters ()

This resets all the available filters and related messages.

 

public setParentBox (

        pParentBoxId in String )

This is used to attach the JFileBrowser to the parent dialog box whose identifier is given as a parameter.

 

The JFileBrowser is then modal and transient for the parent dialog box.

 

Saying that a view "v1" is transient for a view "v2" means that:

·         "v1" cannot be iconified.

·         "v1" is automatically unmapped when "v2" is iconified.

·         "v1" is always on top of "v2" (in the Windows stacking order).

 

 

JFileBrowser example

 

// First argument corresponds to the id of the

   transient view (or "")

// Second argument corresponds to the title of the file

   browser

// Last argument corresponds to the default path.

JFileBrowser fileBrowser = createJFileBrowser

   ("", "Open a file...", "C:\work\");

 

// Set the type of the file browser. Allowed types are

   JSaveFileType and JOpenFileType

fileBrowser.setType (JOpenFileType);

 

// Add a filter on the browser

fileBrowser.addFilter ("*.txt", "*.txt Text files");

 

// Show the box and display the result in the console

StdOut.write(fileBrowser.get(), NL);

 

// Don't forget to destroy the box

fileBrowser.delete();