Search code examples
javafxfilechooser

JavaFx FileChooser user defined filename


I'm trying to use FileChooser, but I'm stuck with a trivial problem: after opening a FileChoser window, I can't seem to change the initial filename. This seems like a textbook task, but it got me. Here is the code, which I'm trying to use:

FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save Image");
fileChooser.setInitialFileName("capture");
fileChooser.getExtensionFilters().addAll(
    new FileChooser.ExtensionFilter("JPG", "*.jpg")
);

File file = fileChooser.showSaveDialog(this.primaryStage);

Solution

  • Okay, I've found the culprit. The problem was with that I was using system-hook (https://github.com/kristian/system-hook), and this if the hook is initialized with raw=true value, the UI elements keyboard listeners stops working properly, reasons unknown. Using raw=false fixes this.