I used the JFileChooser.showOpenDialog to open the dialog box. When it is show up, there is "open" on the title of dialog box. I want to change it to be "Add" because my code is for adding a new file. Would someone tell me how to do it. Thanks in advance.
There is my dialog box.
JFileChooser has a method, getSelectedFile(). Which is a File. If you open the dialog with showSaveDialog() you should be able to get the File from that (file. getName()).
As you have seen, the JFileChooser class provides the showOpenDialog method for displaying an open dialog and the showSaveDialog method for displaying a save dialog. The class has another method, showDialog , for displaying a file chooser for a custom task in a dialog.
JFileChooser. setMultiSelectionEnabled(true) − To enable the multiple selection of file.
JFileChooser's showOpenDialog does not give you the option to change the title of the dialog box (see docs). You have to use a bit more code for that. The code example in the documentation comes close:
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter);
chooser.setDialogTitle("Add new file");
int returnVal = chooser.showOpenDialog(parent);
It is possible to customize the dialog before the filter.
JFileChooser fc = new JFileChooser();
fc.setDialogTitle("Title");
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With