Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you change the appearance of a JavaFX FileChooser using CSS?

Tags:

java

css

javafx

I'm looking to change the appearance of a FileChooser using CSS. Doing this using SceneBuilder would also be nice please, but since FileChooser does not belong to javafx.scene.controls there doesn't appear to be a straightforward way to do this. I would like to be able to set things such as font, colors, etc. I'd prefer to do this through CSS, but I don't see how to do this directly in the Java code either. Thank you for any assistance.

like image 962
Alan Avatar asked May 27 '15 15:05

Alan


People also ask

Can I use CSS with JavaFX?

The default css is always applied to every JavaFX application. However, you can create one or more custom stylesheets of your own and add them to your application to override the default styles defined by JavaFX.

Where do I put CSS in JavaFX?

In the Properties tab, under the 'JavaFX CSS' section, click on the 'Stylesheets' option. Select the CSS file, and that's it.

What is FileChooser in JavaFX?

FileChooser class is a part of JavaFX. It is used to invoke file open dialogs for selecting a single file (showOpenDialog), file open dialogs for selecting multiple files (showOpenMultipleDialog) and file save dialogs (showSaveDialog). FileChooser class inherits Object class.


1 Answers

The native operating system's window manager handles the Open/Save dialog. Since FileChooser is a final class this won't be possible. You would have to implement your own custom control to customize the style.

Check this link for a project on GitHub, FileChooserFx, that attempts to do just that. They provide a "FileChooser" from scratch approach that you could implement in your code.

like image 113
Dustin R Avatar answered Oct 01 '22 23:10

Dustin R