A component is created with the current LAF. So you can try something like:
- Set LAF to the system LAF
- Create the JFileChooser
- Reset the LAF to Nimbus
Not sure is this will cause any problems with the file chooser or not.
سؤال
I want to have my JFileChooser use the system's LookAndFeel, but have the rest of my components use Nimbus. Since each platform provides a different FileChooserUI, how would I set the FileChooserUI property in UIManager to the system's LookAndFeel?
المحلول
A component is created with the current LAF. So you can try something like:
Not sure is this will cause any problems with the file chooser or not.
نصائح أخرى
If you are using windows you can use Windows file chooser :
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class FileSelection {
public static String getPath(){
String path =null;
Display display = new Display ();
Shell shell = new Shell (display);
// Don't show the shell.
//shell.open ();
FileDialog dialog = new FileDialog (shell, SWT.OPEN | SWT.MULTI);
path=dialog.open();
shell.close();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
return path;
}
}
getPath()
will returns the direct path to the selected file, but note that you must download org.eclips.swt
package and add the .jar
file to your class path.
You can download it here : Download
If you are not interesting of using this filechooser then Check this example.