r/java • u/Gleethos • Sep 18 '26
The Successor to Swing Is Finally Here
...and it is still just Swing.
For the last few years, our team at Global TCAD Solutions has been building our products on top of an open-source library called SwingTree.
The idea behind it was pretty straightforward: we wanted to keep Swing but get rid of a lot of the tedious ceremony that comes with when building modern UIs in it.
So instead of constructing and wiring up a component hierarchy imperatively, you can describe it declaratively:
UI.panel("fill")
.add("grow",
UI.button("Hello")
.onClick(it -> doSomething())
);
On top of declarative code, SwingTree also ships a versatile styling API.
It has a CSS-inspired style engine with selectors, specificity, cascading, semantic groups, themes, gradients, shadows, animations, and more. And it all works with actual Swing components underneath.
So you can take an existing Swing application and introduce SwingTree piece by piece. You can use your own "JComponent"s, existing Swing components, SwingTree components, or mix all three.
We've also ended up building quite a bit around the UI layer over the years: reactive properties, immutable state, lenses, reactive & responsive layouts as well as other things that make large GUI applications easier to develop.
This has been a team effort, and SwingTree is now the foundation we're using for our current and probably future TCAD applications. It's been through quite a bit of real-world use as a result.
So our team figured the Java community might be interested in it:
21
u/davidalayachew Sep 18 '26
Very cool. I do a lot of Swing development on a daily basis, so this looks relevant to me.
But everytime I see a Tree-style or Builder-style coding strategy, I have to ask -- how do you handle 2 components that reference each other?
For example, let's say I have a
JButton("Clear")and aJTextField. When the button is pressed, it clears theJTextField. But if the text field is empty, the button is deactivated.How would I model that with your API?
From what I can see by reading the README, you are able to construct a beautiful UI, but how do I extract these components to be able to use later? For example, to add the relevant functionality?
For example, your calculator example -- you created all of those buttons inline, which means that they are not attached to variables. How do I reference them later, to be able to add the logic of addition and subtraction?
A common design problem with physical calculators that can be fixed with software calculators is that, sometimes, you can't press certain buttons after other buttons.
For example, if I press
1then.then0, I should NOT be able to press.again. That's an illegal state!If you think about it, something like a calculator is nothing more than a State Transition Diagram, and part of that is making illegal states unreachable and unrepresentable.
Just like how the Clear button in my first example deactivates when the text field is empty, the UI should be able to prevent illegal states. Doing so handles so many error cases long before they can evolve into something uglier and harder to track down later.
Anyways, the value of your tool is clear. And no matter what, I think it will be useful for at least the construction of the visual side of things. I'm just curious how it handles the interleaving and circular-referencing logic side of things too.
Thanks for posting this.
15
u/MinimallyLoquacious Sep 18 '26
I often wonder why there are those who try to eliminate imperative programming, I like it.
5
u/vmcrash Sep 18 '26
So it is just an extension on top of Swing, right? No alternative that would continue to work if Swing would be ditched sometimes in the future.
7
u/Terrible-Falcon-917 Sep 18 '26
check https://github.com/JetBrains/compose-swing-ui
3
u/agentoutlier Sep 18 '26
I like it.
As for the
SKILL.md... like I get people doing that to show their app is AI agent friendly but you realize its just good documentation.AI agents don't need those markdown files now. If your projects is well documented for humans, produces quality errors when things go wrong it will work for AI agents.
4
u/paul_h Sep 18 '26
I love declarative markup and have been using swing on and off since the 90s. What does single source file calculator look like? Ref https://paulhammant.com/2024/02/14/that-ruby-and-groovy-language-feature/
1
u/CutGroundbreaking305 Sep 18 '26
Hey do you remember me Big people 😮 swing alternative but GUI isn't used much compared to web and javafx exists I guess Anyways great project
3
u/GoogleIsYourFrenemy Sep 18 '26
Hey, can you put a jtable inside a panel inside a jtable and have the outer jtable row grow/shrink with the inner jtable? Oh and I'd like to have functional sorting on the inner table on a per outer cell basis. Oh and I'd love hover tips to work for the inner table cells without activating the outer cell for editing.
I know. I'm a monster.
1
u/HyperspaceFrontier Sep 18 '26
I bet you to try Compose Multiplatform (though it requires Kotlin). It renders in a Swing window on Java, yes, but from here it is another universe: fast, modern, and much easier to implement.
2
u/mollari222 Sep 18 '26
Looks very interesting. I will further evaluate it for my Admin-Frontends. At the moment i use vaadin, but a good old Desktop-native admin GUI would be nice ;-)
2
u/headius Sep 19 '26
I like this. I want to try using it from Ruby with JRuby because the pattern fits much better than classical Swing.
Here's a small Swing example from JRuby:
https://github.com/jruby/jruby/blob/master/samples/swing2.rb
SwingTree would fit naturally into a Ruby style!
0
u/temo987 Sep 18 '26
Isn't JavaFX better?
1
u/AdministrativeHost15 Sep 18 '26
I remember when Swing was the hot thing back the 1990's. I hoped to build applets using it. But no luck.
1
u/Drawhoe Oct 07 '26
Filthy Rich Clients was a great book. It showed me why we needed something like JavaFX.
1
u/raviteja777 Sep 18 '26
wasn't that supposed to be JavaFX ? But either way people are still developing java desktop applications ?
-5
u/dmigowski Sep 18 '26 edited Sep 18 '26
So swing has become even slower now? Isn't that just JavaFX now?
Edit: Calm down dudes, it was a honest question.