Desktop

File dialogs

Open the native open, save and folder dialogs from Java or from the page, without the page ever seeing a file path.

A page never sees a file's path. Use the operating system's dialogs through the window. Available since 0.2.4.

From Java

Dialogs dialogs = window.dialogs();
dialogs.saveFile(FileDialogOptions.defaults()
                .withTitle("Export report").withFileName("report.pdf")
                .withFilters(FileFilter.of("PDF documents", "pdf")))
        .thenAccept(chosen -> chosen.ifPresent(path -> writeReport(path)));   // empty if cancelled

dialogs.openFile(FileDialogOptions.defaults());      // also openFiles(...) and chooseFolder(...)

Each call returns a CompletableFuture at once. Cancelling gives an empty result, not an error. withSize(w, h) asks for a bigger dialog (a request: the system owns it).

From the page

To let the page save a file, call window.enableSaveAs() in Java and jolt.saveAs in the page:

const saved = await jolt.saveAs(blobOrBytesOrText, { name: "report.pdf", filters: [{ name: "PDF", extensions: ["pdf"] }] });
// { name, size } or null if cancelled; the page never learns the path

The data is written to a temporary file and moved into place when complete. Only trusted origins may use it, and on Linux the page must come from loadResources.