Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the title of the JFileChooser dialogbox

Tags:

java

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. enter image description here

like image 434
user819774 Avatar asked May 11 '15 19:05

user819774


People also ask

How do I find my JFileChooser file name?

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()).

What is the main purpose of using JFileChooser?

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.

How do I select multiple files in JFileChooser?

JFileChooser. setMultiSelectionEnabled(true) − To enable the multiple selection of file.


2 Answers

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);
like image 150
fleed Avatar answered Sep 19 '22 18:09

fleed


It is possible to customize the dialog before the filter.

JFileChooser fc = new JFileChooser();

fc.setDialogTitle("Title");

fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
like image 21
hexadecimal Avatar answered Sep 17 '22 18:09

hexadecimal