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?
Asked
Active
Viewed 352 times
0
2 Answers
2
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.

camickr
- 321,443
- 19
- 166
- 288
-
There could be a nicer solution, but this works. Thanks! Edit: There are some discoloration issues on the file chooser, but it's functional. – Technius May 05 '13 at 22:55
-
:-) not I think that not, different L&F can be applied for each of Top-Level Containers, seems like as in Java7 reduced, Bug, Whatever, to only for decorated container (shaped or translucent container isn't possible for changed L&F, nor undecorated) – mKorbel May 06 '13 at 12:14
0
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.