Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with setting JFileChooser approve button  RSS feed

 
Tony Chow
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have started making a text editor recently. I have my code like this:



I can compile the code and use the text editor without any problems. However, when I click the "Open" or "Save" button to launch the JFileChooser, the first time the setApproveButtonText() doesn't take any effect. The approve button text is still the old one. However, if I close the JFileChooser and open it again, the text is changed.

So the problem is, how to make the new approve button text takes effect in the first run of the JFileChooser? Thanks for any help.
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
381 lines of code is too much to read.

Your question is about displaying a JFileChooser. So create a SSCCE that demonstrates the problem. The SSCCE should just be a simple frame with a button and an ActionListener to display the JFileChooser.
 
Tony Chow
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright in fact I just write the JFileChooser like this:



So I want to set the approve button text by chooser.setApproveButtonText("Choose"); , but the problem occurs.
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this. Apparently I've solved this issue before.

However, this solution is not the only one. I remember seeing the same issue somewhere else just a short while ago, and there the solution was to follow this sequence:
1) call setDialogType(SAVE_DIALOG). This will reset the approve button text.
2) call setApproveButtonText with the value you want.
3) call showSaveDialog or showDialog, it doesn't really matter which one. showSaveDialog will call setDialogType(SAVE_DIALOG) before calling showDialog but because that is already the current dialog type nothing is done.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!