问题
I have an installer program that lets the user choose a directory in which to install. The JFileChooser implementation on MacOS uses a native dialog (or at least it looks native). That's great.
The only problem is there's no way to create a directory from this dialog ... you can only choose a pre-existing one, which is clunky. Is there a way to get this functionality?
I use the JFileChooser in "select directories only" mode. Thus it isn't the same dialog as the usual MacOS file picker which does have that functionality.
回答1:
That is correct that the showOpenDialog method will not give you an option to create new folders. This is a usability thing as it does not really make sense to open something that does not exist. If you use the showSaveDialog there will be a button 'Make new Folder' or similar to that.
回答2:
public static void main(String[] args) {
JFrame frame = new JFrame();
FileDialog d = new FileDialog(frame);
d.setVisible(true);
}
来源:https://stackoverflow.com/questions/845403/how-can-i-make-a-jfilechooser-on-the-mac-that-lets-users-create-directories