1. Component
Event<?> close = Event.event();
JButton closeButton = Components.button()
.control(Control.builder()
.command(close::run)
.caption("Close"))
.build();
Dialogs.builder()
.component(closeButton)
.owner(window)
.title("Dialog")
.disposeOnEscape(false)
.closeObserver(close)
.show();
2. Selection
2.1. Items
Dialogs.select()
.list(List.of("One", "Two", "Three"))
.owner(window)
.title("Select a number")
.select()
.single()
.ifPresent(System.out::println);
Collection<String> selected = Dialogs.select()
.list(List.of("One", "Two", "Three", "Four"))
.owner(window)
.title("Select numbers")
.select()
.multiple();
2.2. Files
File file = Dialogs.select()
.files()
.owner(window)
.title("Select a file")
.selectFile();
Collection<File> files = Dialogs.select()
.files()
.owner(window)
.title("Select files")
.filter(new FileNameExtensionFilter("PDF files", "pdf"))
.selectFiles();
File fileToSave = Dialogs.select()
.files()
.owner(window)
.title("Select file to save")
.confirmOverwrite(false)
.selectFileToSave("default-filename.txt");
File directory = Dialogs.select()
.files()
.owner(window)
.title("Select a directory")
.selectDirectory();
Collection<File> directories = Dialogs.select()
.files()
.owner(window)
.title("Select directories")
.selectDirectories();
File fileOrDirectory = Dialogs.select()
.files()
.owner(window)
.title("Select file or directory")
.selectFileOrDirectory();
Collection<File> filesOrDirectories = Dialogs.select()
.files()
.owner(window)
.title("Select files and/or directories")
.selectFilesOrDirectories();
3. Action Dialogs
4. Input
ComponentValue<NumberField<Integer>, Integer> component =
Components.integerField()
.value(42)
.buildValue();
Integer input = Dialogs.input()
.component(component)
.owner(window)
.title("Input")
.valid(State.present(component))
.show();
5. Exception
Dialogs.exception()
.owner(window)
.title("Exception")
.unwrap(List.of(RuntimeException.class))
// Don't include system properties
.systemProperties(false)
.show(exception);
6. Calendar
Dialogs.calendar()
.owner(window)
.title("Calendar")
.selectLocalDate()
.ifPresent(System.out::println);
7. Progress
Progress dialogs provide feedback during long-running operations. To prevent unnecessary visual noise, progress dialogs support configurable delays for both showing and hiding the dialog.
The .delay() method accepts two parameters: the delay before showing the dialog (in milliseconds) and the delay before hiding it. These delays are based on human-computer interaction research:
-
Show delay (350ms default): Operations completing in under ~300ms feel instantaneous to users, so showing a progress indicator would be distracting. A delay of 350ms ensures the dialog only appears for operations that users actually perceive as taking time.
-
Hide delay (800ms default): When an operation completes just after the dialog appears, hiding it immediately would create a jarring flash. The hide delay smooths this transition and reduces the perceived duration of short operations by avoiding the visual disruption of rapidly appearing and disappearing dialogs.
Dialogs.progressWorker()
.task(this::performTask)
.owner(window)
.title("Performing task")
.delay(500, 1000)
.onResult(this::handleResult)
.onException(this::handleException)
.execute();