DEV Community

Cover image for Swing theming: Basic introduction to MaterialTheme System
Vincenzo Palazzo
Vincenzo Palazzo

Posted on

1

Swing theming: Basic introduction to MaterialTheme System

Since 2019, material-ui-swing has an experimental feature that is called MaterialTheming. In particular, MaterialTheming is a proposal to add a declarative Theme system inside Swing like the material theming system implemented in Flutter or Jetpack Compose.

Image description

Introduction to Material-UI-Swing

Material-UI-Swing is a library that gives the possibility to import material style inside a very old framework like Swing with the original swing API. The library was originally born as College Project by atharva washimkar and transformed into a product by vincenzopalazzo.

In addition, the original project was forked by vincenzopalazzo because he started to implement some experiments in his own repository, after that, the repository https://github.com/vincenzopalazzo/material-ui-swing was the only repository maintained, but periodically the atharw's receive synchronization with the last update.

After the original maintainer left the project as maintainer in 2018 and the vincenzopalazzo new maintainer begin in 2018 until now, the scope development of the library start to be to grow as a product. This was also possible by the support from Arizona State University during the integration of the library with one of the most popular Swing software in the world which is JMars.

The development of the library was focused to experiment with some solutions that provide the building blocks for the end developers to implement any type of style that the user wants without using a standard palette built inside the library.

This opens two problems, that are described below:

  • Implementing a dynamic component that is able to change with user settings can be difficult because can contain a lot of corner cases.
  • Swing framework has no easy concept of theme inside (a theme in the sense of Style and not only colors), but that can also change the style of one component.

Introduction to MaterialTheming System

Material Theming system provided of constant build in the library under a MaterialTheme interface and with this concept to have an interface that provides the access to all the value that Swing process to build and styling the UI material-ui-swing is able to support external theme provided in separate jars that include only the style of the application.

One example of an external theme is DarkStackOverflowTheme, and this is an important feature to have inside a UI toolking.

In contrast, the MaterialTheme interface can be improved and allowed different formats of configuration, by file propriety or JSON, and so on.

This is particularly powerful when the user wants to import some theme from external resources like the Intellij themes or others.

Example of Usage

Change theme is super easy and doesn't require you to make any change inside the repository, you can have inside the static block the following code

static {
    try {
      // UIManager.setLookAndFeel(new MaterialLookAndFeel(new MaterialLiteTheme()));
// by including the https://github.com/material-ui-swing/DarkStackOverflowTheme
     UIManager.setLookAndFeel(new MaterialLookAndFeel(new DarkStackOverflowTheme())); mouse hover
    } catch (UnsupportedLookAndFeelException e) {
      e.printStackTrace();
    }
Enter fullscreen mode Exit fullscreen mode

Conclusion

After many years I start to share my experiment started on material-ui-swing to implement a custom theme, and implement an alternative library to modernize Swing application.

If you like my work considered to sponsor me on Github sponsor page and follow me on Github @vincenzopalazzo

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI Live!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️