0

How do you change the button text of FileDialog (not JFileChooser)? The two modes specify the button text:

FileDialog.LOAD -> "Open"
FileDialog.SAVE -> "Save"

But I want the button to say something else. Is it possible to change this text?

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
martinez314
  • 12,162
  • 5
  • 36
  • 63
  • Question edited: Swing tag removed and AWT tag added. FileDialog is not a Swing class but rather an AWT class. – Hovercraft Full Of Eels Aug 11 '15 at 20:40
  • Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT using components in favor of Swing. – Andrew Thompson Aug 13 '15 at 11:32
  • @AndrewThompson I agree about using Swing over AWT. The only AWT component in the whole app is FileDialog since on OS X, Swing's JFileChooser looks terrible. – martinez314 Aug 13 '15 at 13:22

2 Answers2

1

You cant change button text only with FileDialog methods, the only text you can edit in it is window's title which opens when you press for example "Open".

FileDialog fd = new FileDialog(FdExample.this, "select File", FileDialog.LOAD);
fd.setTitle("any new title");

If you want custom text in button, you can use JButton and ActionListener to activate FileDialog. Probably this will be the best way.

DontPanic
  • 1,327
  • 1
  • 13
  • 20
0
FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell(),SWT.SAVE);
prithivraj
  • 71
  • 1
  • 12
  • Thank you for this code snippet, which may provide some immediate help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its educational value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with similar, but not identical, questions. Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. In particular, where is the text you're assigning to the button labels? – Toby Speight Jul 21 '17 at 10:11