How to change the name of the JFileChooser dialog box

I used JFileChooser.showOpenDialog to open a dialog box. When it is displayed, "open" appears in the title bar of the dialog box. I want to change it as "Add" because my code is for adding a new file. Someone will tell me how to do this. Thanks in advance.

There is my dialog box. enter image description here

+6
source share
2 answers

JFileChooser showOpenDialog does not give you the ability to change the title of the dialog box (see docs ). For this you need to use some more code. The sample code in the documentation is 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); 
+4
source

You can customize the dialog before the filter.

 JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Title"); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 
+2
source

Source: https://habr.com/ru/post/986996/


All Articles