Apache NetBeans
Apache NetBeans
Latest release

Apache NetBeans 24

Download

I have a Node.Property for a file. How can I control the file chooser that is the custom editor?

A number of the built-in property editors in NetBeans can have their behavior controlled by passing "hints" to them. Hints are providing by calling setValue("something", someValue) on the Node.Property. For example, to suppress the custom editor button for a property, use

 Node.Property<String> myProp = new MyStringProp();
 myProp.setValue ("suppressCustomEditor", Boolean.TRUE);

The built-in property editors for files and arrays of files support a number of hints:

String Hint Name Value Type Effect

filter

java.io.FilenameFilter or javax.swing.filechooser.FileFilter or java.io.FileFilter

Sets the file filter used by the file chooser

directories

java.lang.Boolean

Set the file chooser to accept only directories. If combined with the "files" hint set to true (see below), will accept both directories and files.

files

java.lang.Boolean

Set the file chooser to accept only files (unless combined with the "directories" hint set to true above - in which case simply not using either hint has the same effect

currentDir

java.io.File

The directory the file chooser should default to when it is first opened

baseDir

java.io.File

The base directory for the file property. This is needed only if the file has a relative path. Java files are just wrappers for a path name, and need not exist on disk. So if the file property is foo/MyFile.txt that is a perfectly legal file name (presumably the Java Bean or Node the property belongs to knows how to find the parent directory of "foo"). The file chooser needs to know the full path to foo/ - so you would pass a file here to provide the parent folder for foo/. For example, if the complete path to MyFile.txt is /Users/tim/Documents/foo/MyFile.txt, you would call setValue("baseDir", new File("/Users/tim/Documents")

file_hiding

java.lang.Boolean

Value to call JFileChooser.setFileHidingEnabled() with (remember, if your filter filters out directories and you set file hiding enabled, the user will not be able to usefully change directories)

The built-in bean property editors in NetBeans are found in the package org.netbeans.beaninfo editors in the module o.n.core in NetBeans' sources.