Reputation: 2562
I was just wondering: how does Gmail use the Windows/Mac file chooser to upload files? Is there any way to do this in Java?
Personally, I don't like the way that the JFileChooser
looks like, and I thought it would be better for my users to be able to use something that they're more used to. Tips anyone?
Upvotes: 20
Views: 22524
Reputation: 42060
The SWT components have always looked the same styles that are in the running OS. You can see some examples:
It was assumed that from version 7 of Java, Swing styles would be more like that of operating systems, but may see it in Java 8.
Upvotes: 3
Reputation: 11909
Use the old java.awt.FileDialog instead:
new java.awt.FileDialog((java.awt.Frame) null).setVisible(true);
Upvotes: 22
Reputation: 4704
You can try using JFileChooser but setting the look and feel to be the platform look and feel:
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception ex) {
ex.printStackTrace();
}
And that would make all the swing components look nicer!
Upvotes: 15
Reputation: 47637
GMail is a web application that eventually relies on the browser to show this component. Now a good solution is to use the Native Look&Feel of the system which provides a JFileChooser quite similar to what you show:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
EDIT: Pulsar's solution is even better since it provides the exact dialog you are looking for. I am not sure that it provides all the features of the JFileChooser.
Upvotes: 6