fxconcepts
fxconcepts

Reputation: 3

How to control size of FileChooser dialog in JavaFX

I want to set FileChooser dialog preferred size. For now, it cannot be set and just appears with fixed size always (occupied with almost full screen). I can't find resizing method in FileChooser intance and even control dialog after it appears.

Upvotes: 0

Views: 325

Answers (2)

trashgod
trashgod

Reputation: 205785

As noted here, the JavaFX FileChooser is provided by the host platform. In particular, "For configuration properties which values haven't been set explicitly, the displayed dialog uses their platform default values." Presumably, this includes size.

  • On macOS, Java/FX 17 LTS, if you resize the dialog, the new dialog size is saved as a preference; when invoked again, the last used dialog size is restored.

Please feel free to add your user experience on other platforms. This FileChooserDemo can be used for testing.

Upvotes: 1

Duff
Duff

Reputation: 300

I don't think that this is possible. The documentation of FileChooser states

Provides support for standard platform file dialogs. (...) The configuration of the displayed dialog is controlled by the values of the FileChooser properties set before the corresponding show*Dialog method is called. This configuration includes the dialog's title, the initial directory displayed in the dialog and the extension filter(s) for the listed files.

The popup dialog is provided by your operating system, so it cannot be customized directly. Your only option is using the bit of API that the FileChooser class itself provides. Since JavaFX is a cross platform UI framework, the customization options probably have been limited to the ones that are supported natively by all major platforms.

If you absolutely must customize the file chooser, you can try to embed a Swing JFileChooser in your JavaFX app.

Upvotes: 3

Related Questions