Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX-8 GUI for desktop apps: Are there Look & Feels like in Swing?

In Swing, there were some Look & Feels provided as a part of Java, e.g.:

Cross Platform:

  • Nimbus
  • Motif
  • Metal

Specific to platforms:

  • GTK+
  • Windows XP
  • etc.

Does Java 8 supply Look & Feels for JavaFX like it did for Swing? (I don't ask about a specific Look & Feel, I ask in general if there are Look & Feels additional to the default one)

like image 359
SomethingSomething Avatar asked Mar 11 '15 15:03

SomethingSomething


People also ask

Is JavaFX good for desktop applications?

JavaFX is a very power full way of creating GUI applications for the developers who are familiar with Java, but none of any updates happened for javaFX in java newer versions. and in Java 13, some of the previous features are not included.

What is the difference between JavaFX and GUI?

Swing is the standard toolkit for Java developer in creating GUI, whereas JavaFX provides platform support for creating desktop applications. Swing has a more sophisticated set of GUI components, whereas JavaFX has a decent number of UI components available but lesser than what Swing provides.

Which is better JavaFX or Swing?

Swing has a wider range of UI components compared to FX, but FX adds more all the time, so this difference might not be notable much longer. Likewise, JavaFX offers IDE support, but Swing's IDE support is more mature and has more options for rapid deployment needs.

Is JavaFX replacing Swing?

Is JavaFX replacing Swing as the new client UI library for Java SE? Yes. However, Swing will remain part of the Java SE specification for the foreseeable future, and therefore included in the JRE.


1 Answers

I will answer my own question with a summary of the responses to this question and with a little research I made by myself:

  • In JavaFX, there is no Look & Feel term anymore, but there are Stylesheets
  • Until JavaFX-8 (I.e. the Java 8 version), there was only one provided stylesheet, named Caspian
  • Starting from JavaFX-8, another stylesheet was added, named Modena. The Modena stylesheet is the default one in JavaFX-8

It is possible in to switch between Modena and Caspian stylesheets using the following commands:

setUserAgentStylesheet(STYLESHEET_CASPIAN); // Switches to "Caspian"
setUserAgentStylesheet(STYLESHEET_MODENA);  // Switches to "Modena"

Note that:

  • setUserAgentStylesheet(String url) is a method of the class Application
  • The constants STYLESHEET_CASPIAN and STYLESHEET_MODENA are class members of Application
  • The code shown above should be called on the JavaFX Application thread
  • STYLESHEET_CASPIAN and STYLESHEET_MODENA contain urls. You may use your own stylesheets using the method, passing it the url to your stylesheet

    • For example, if I created a stylesheet named DarkTheme.css and placed it in the project directory, under src/resources, I would use the following code to apply it: setUserAgentStylesheet(this.getClass().getResource("resources/DarkTheme.css").toExternalForm());

    • If you just want to extend the current stylesheet, and not to define it all from scratch, you may use instead: scene.getStylesheets().add(this.getClass().getResource("resources/DarkTheme.css").toExternalForm());

like image 76
SomethingSomething Avatar answered Nov 15 '22 01:11

SomethingSomething