Pregunta

I want to show a message when the user does not enter a file name on the file chooser text box.

Please let me know if there is a way to accomplish this. My code is below:

FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Save as");

    FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(
        "PDF files (*.pdf)", "*.pdf");
    fileChooser.getExtensionFilters().add(extFilter);
    File destinationFile = fileChooser.showSaveDialog(primaryStage);
¿Fue útil?

Solución 3

This was an issue till java 1.7.0_25(not sure of the exact release) but has been fixed in the release 1.7.0_40.

Also, please see this.

Otros consejos

The FileChooser is implemented using native APIs in JavaFX, so it's behavior is platform-dependent. On Mac OS X for example the FileChooser will disable the "Save" button if the file name field is empty.

However it is now impossible to modify the behavior of the FileChooser dialogs. Which platform are you using? I suppose it's a bug in JavaFX that you are able to select "Save" without providing the file name.

Using JOptionPane you can show dialogs. If you want to show the error message in a dialog, then kindly refer to JOptionPane.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top