Hi folks! It’s been a while since my last post…

Today I have an announcement of a new theme I’ve created. This is a new theme called Transit and it builds upon the lessons learned while developing JMetro.

It is not meant to be JMetro 2, it will be an entirely new theme.

Strengths and Key Principles

This theme follows some of the design principles and has some of the key strengths of JMetro:

  • Modern look and feel;
  • Zero tight coupling with this library:
    • No new controls. “Pluggable” theme. Functionality is added “behind the curtains” to existing JavaFX controls through the Skin API (FXSkins library);
    • Setting and unsetting is seamless and easy (only 1 line of code) even on already existing apps that don’t use this theme;
  • Looks integrated on Windows (80%/90% of desktop users use Windows) also works well on other OSes;
  • Light and Dark versions;
  • Easily override and customize colors by overriding JavaFX CSS variables;
  • Only relies on JavaFX CSS, JavaFX API and Java code (no other “foreign technologies”);
  • Samples and theme tester app on samples sub-project;
  • Lots of real world, recognized Java apps already using it (NASA’s applications, applications used in the White House, etc, etc) (JMetro and Transit) – check the documentation page for more real world examples;
  • Leverages lessons learned developing JMetro theme;

I like to use the term Michael Paus (@MichaelPaus) coined when he was referring to JMetro: this is a “pluggable” JavaFX theme (like JMetro).

This means there’s zero coupling because it doesn’t define any new Controls and the developer only needs to run 1 line of code to set the theme (this is all the coupling you’ll get).

It adds features to the existing JavaFX controls that you regularly use (controls from the standard JavaFX API or from known third party libraries) by leveraging the JavaFX Skin API. This is achieved through the FXSkins library which Transit depends on.

The benefits of this approach are:

  • Really easy to set this theme on an existing app. You’ll have all the added features on your existing controls with almost zero effort;
  • Very easy to switch to another theme either because you want to set another theme on a different environment (OS, etc) or you just want to start using another theme altogether;
  • You’ll keep having features added to the controls you’re using in your application every time there’s a new version of this theme with new features, without the need to change any code. All you need is to update the version of Transit.

High level architecture

FXSkins: The Transit Theme makes use of the FXSkins library. FXSkins adds behavior to existing JavaFX Controls without the developer having to do anything, by leveraging the JavaFX Skin API. For example, one of the controls FXSkins adds features to is the Slider control. It adds a popup that fades in and out when the user drags the thumb, that popup is always located over the thumb and shows the Slider current value. It also adds a fill color to the Slider which the default JavaFX Slider doesn’t have. This is just an example, there are other controls that FXSkins adds behavior to (by setting new Skins on them).

Now the advantage of this architecture for the developer using the library is that you can use FXSkins independent of the Transit Theme. That is, you can have better skins with added features to your standard controls in your already existing themes without having to use the transit theme styles. Or you can even use FXSkins just as is (without any new theme), because it is already, by default, made to look good with Modena (the standard JavaFX theme). Check FXSkins documentation to learn how.

Transit Theme: Adds the CSS styles to your control to make them look more modern. It also adds some more API for added style definitions.

If you want the whole package, add Transit Theme as a dependency and you’ll get the styles and the added behavior on your controls (Transit Theme already depends on the FXSkins library).

New in this release

  • Conscious ScrollPane Skin and style

This new Skin for the ScrollPane will show the scrollbars in a minimal style with just the thumb showing. When the user mouses over the thumb the scrollbars transform to show their full UI. All of this is styleable through CSS: the minimal scrollbar visuals, the full scrollbar visuals, etc.

  • Compatible with latest Java LTS release and JavaFX (Java 17 and JavaFX 20)

At the moment of the writing of this post it is being built using Java 17 and JavaFX 20

  • Clear architectural separation between skins and theme CSS definitions

As mentioned previously there’s now a clear separation between the new skin definition and the CSS theme definition. Transit Theme depends on FXSkins library which is an entirely different library.

Conclusion

A new theme called Transit has just been released, you can head on over to the documentation page or github page for more information.

6 thoughts on “Transit theme released

    • Thanks Saeid and thanks for your contributions to JMetro/Transit!
      I’m glad you like the library.

      Unfortunately, haven’t had time to look at that issue. I’m currently focused on a new library and as all this work is unpaid and I still have to do my day to day paid work, haven’t had enough free spare time.

      But I’ll try to have a look at that as soon as possible.

      Thanks again!

  1. Hey Pedro, that objective of Transit becoming a User Agent Stylesheet would definitely be a worthy one! As you say “Which means that you have to make your rules as specific or more than the rules in Transit if you want to override rules in Transit ” which is a real pain and makes customising a theme onwards tricky.

    • Hey Nick! Hope you’re doing great!

      Unfortunately, the JavaFX SDK doesn’t yet have proper support for User Agent Stylesheets as mentioned in the “Not like Modena” section of the Transit documentation page: https://pixelduke.com/transit-java-javafx-theme/

      I know that the JavaFX team is currently working on it. Hopefully they will fix that soon and I can add user agent stylesheet support to Transit.

      Thanks!

  2. I finally got the chance to switch from JMetro to Transit. I had to make small css tweak (TitlePane padding is zero in Transit but 10 in JMetro) but transition was smooth otherwise. Everything looks identical to JMetro with added benefit that my css files no longer need “!important” tag to override css attributes. Switching back and forth to Modena is also smoother since JMetro used to throw some exception with class cast.

    My only question, now that Transit is superior to JMetro, is there any reason to use JMetro? are you planning to deprecate JMetro?

    • Hi Saeid,

      Glad that the transition was smooth and that you no longer need to use !important in your stylesheets. Not using !important makes your stylesheets more maintainable.

      I might migrate Transit 1.0 (current Transit released version) to a JMetro new release since it’s basically just an improved version of JMetro.

      Having said that you’re safe to replace JMetro with Transit 1.0… I might release a new version of JMetro that is pretty much Transit 1.0, it will likely be a straight-forward migration for you. I don’t have plans to release any update to JMetro that will diverge from Transit 1.0.

      BTW, I’m already working on a new version of Transit which looks considerably different (I’ve been posting updates on Twitter).

      This new version of Transit I’m working on is really a distinct thing from JMetro. It still uses some of the work I’m done but the outcome looks much different.

Leave a Reply

Your email address will not be published. Required fields are marked *