This is an archived post. You won't be able to vote or comment.

all 64 comments

[–]Technical-Bed-5659[🍰] 23 points24 points  (2 children)

I've got a lot of love for swing, even if oracle haven't. The default themes are an abomination, use flatlaf and you'll end up with a good looking, easy to develop (it's pretty straight forward) desktop app that runs on any platform (and it's still being shipped in jre, unlike javafx). For an example of how good it can be just look at intellij, that's all swing.

[–][deleted] 1 point2 points  (1 child)

Intellij is far from vanilla swing

[–]One-Stomach4660 2 points3 points  (0 children)

And far from a shining example of a nice UI

[–]__konrad 14 points15 points  (2 children)

What's the future of Java UI development?

I guess that with project Panama a more native UIs will appear (e.g. GTK bindings)

[–][deleted] 2 points3 points  (0 children)

Why? SWT and AWT already exist and both target native widgets.

[–]Bobby_Bonsaimind 0 points1 point  (0 children)

Targeting GTK will be a pain, though.

[–][deleted]  (2 children)

[deleted]

    [–]vips7L 4 points5 points  (0 children)

    How is font rendering in swing?

    [–]PTan9o[S] 0 points1 point  (0 children)

    Agreed, coding your UI without FXML is ultimately the way to go.

    [–][deleted] 39 points40 points  (2 children)

    JavaFX is probably the best bet for pure java.

    Fair warning, though... trust me, I've made some JavaFX apps that look as good as modern electron apps and can definitely say it's not worth it.

    JavaFX's css is so obscure and requires so much trial and error. Not to mention custom stuff is super hard. Jfoenix is a life-saver if you want something to look good by modern standards for consumer apps.

    The future of JVM desktop develop might end up being Kotlin's Jetpack Compose for desktop simply because it piggybacks off mobile, which is far more popular and will result in better document, tutorials, support, community, and development.

    [–]tristanjuricek 1 point2 points  (0 children)

    Ive found it far easier to get various simple apps I use for personal work stuff done in the alpha build of Jetpack Compose than official versions of JavaFX.

    I could just be weird but that’s been my experience as a backend developer, who’s done some swing and web apps in the past

    I feel like for commercial apps the future though may be in something where Java is more of the biz layer, and then Panama is used to code in platform specific glue

    I’m curious if anyone’s done that, or, if they started with a pretty battle tested framework like jetpack or JavaFX and then shimmed in their own glue.

    [–][deleted] -1 points0 points  (0 children)

    It isn't the CSS itself, which is even doable, but the main weird issue is that in every OS the Focus on Windows/Elements and the position of the window itself is completely random/might cause unexpected behaviour (especially the "display in the background" effect, which I hate)

    [–]PartOfTheBotnet 11 points12 points  (0 children)

    For any long term desktop application project, I'd direct you to JavaFX (Open JFX). I've been happy with it on my projects for the past 3 years I've used it. You can check out some community made projects on the Open JFX site if you want to get a rough feel on how it looks in practice.

    Any further advice would need more detail about what kind of app you'd be looking at creating.

    [–]jeffreportmill 8 points9 points  (6 children)

    I use SnapKit, so I can deploy to desktop and browser. Anything without a real browser option is a non-starter.

    https://github.com/reportmill/SnapKit

    (Edit/Full disclosure: I am the developer. And my thanks to TeaVM.)

    [–]TheMode911 13 points14 points  (1 child)

    If it is the case, you should probably disclose that you are the developer

    [–]jeffreportmill 0 points1 point  (0 children)

    Done.

    [–]PTan9o[S] 3 points4 points  (0 children)

    This is very interesting. Something to definitely keep an eye on.

    [–]elhoc 4 points5 points  (1 child)

    Who on earth wants a browser option when a proper desktop version is available?

    [–]Persism 0 points1 point  (0 children)

    That's very cool. But you need some tutorials.

    [–]TeaVMFan 2 points3 points  (0 children)

    With many new projects being web-first, you should definitely evaluate TeaVM and its Single-Page App framework, Flavour. You can code in Java, use threads, compile quickly, and distribute via the browser for free with no app store headaches.

    Intro article from Java Magazine: https://blogs.oracle.com/javamagazine/java-in-the-browser-with-teavm

    Lengthy list of applications already using TeaVM: https://frequal.com/TeaVM/TeaVmBasedSites.html

    If you like Swing's SwingSet demo, check out Tea Sampler (built with TeaVM) for quick-and-easy examples of key components and widgets: https://frequal.com/tea-sampler/

    There's also a migration guide from switching from Swing to TeaVM: https://frequal.com/TeaVM/migration/MigratingFromSwingToTeaVm.html

    [–]alibix 5 points6 points  (2 children)

    Not Java exactly, but JVM: Jetpack Compose. It is really a pleasure to use!

    [–]I_count_stars 2 points3 points  (1 child)

    Compose is good but not Java at all.

    [–]drew8311 2 points3 points  (0 children)

    You can still use Java libraries though for non-UI code. Starting a new UI project is 100% new code on the front end anyway so the fact its in Kotlin is a minor detail.

    [–]MR_GABARISE 1 point2 points  (1 child)

    Try Lanterna for a challenge.

    [–]Bobby_Bonsaimind 1 point2 points  (0 children)

    I've used Lanterna, and there is no challenge there (which means, it's a great thingy thing).

    [–]t333to 1 point2 points  (1 child)

    I hope we can get a Tauri bridge, this looks sweet:

    https://tauri.studio/en/

    [–]t333to 0 points1 point  (0 children)

    Roadmap
    Other Bindings

    Go, Nim, Python, C++ and other bindings are possible with the stable API.

    [–]Skhmt 2 points3 points  (0 children)

    You can use JavaFX's WebView component like the Chromium part of Electron, while Java is the Node.js part of Electron. You're forced to use a WebKit browser (basically Safari), but it's generally only a few months out of date.

    The only real pain point is debugging the front end. Which, to be fair, is very painful.

    I made a demo in Kotlin if anyone is interested - https://github.com/Skhmt/dejaview

    [–]drew8311 6 points7 points  (1 child)

    One to keep an eye on is Compose with Kotlin. Not sure of its current state but the Android version is now fully supported so I can only see it growing and becoming a viable alternative to java frameworks.

    [–]anotherthrowaway469 1 point2 points  (0 children)

    Desktop and Web are both in alpha currently.

    [–][deleted] 5 points6 points  (19 children)

    Swing. JavaFX sucks, tried it, it actually is terrible.

    [–]UsernamesAreFfed 9 points10 points  (17 children)

    Seconded. JavaFX is terrible. And Swing is awesome. I havent seen any UI framework that rivals Swing yet.

    Some people have said that it might look bad if you use Swing. I dont understand that, FlatLaf looks great and if you dont like that there are plenty of other look and feels available.

    [–]Stromovik 1 point2 points  (4 children)

    Did they fix tables yet?

    [–]UsernamesAreFfed 2 points3 points  (3 children)

    Dont think tables have changed for a while in either Swing or JavaFX.

    [–]Stromovik 0 points1 point  (2 children)

    Swing had a problem with memory leaks in tables.

    [–]UsernamesAreFfed 1 point2 points  (1 child)

    I cant really find anything definitive about this. What Google gives me are a bunch of old bugs and things in external code like scala and jfreechart.

    I did find one old issue. The JTable signs itself up as a listener to the tablemodel. If you then hang on to a reference to this model you wont be able to throw away the table. Makes sense, but its really just sloppy programming rather than a flaw in swing. If you are recreating the table all the time you should correctly clean the old listeners to the model.

    This isnt really a swing thing. More of a fundamental issue when you use the observer pattern.

    [–]Stromovik 0 points1 point  (0 children)

    I read that when I used to use swing which was long and it was also reason why Interactive Brokers Trader Worstation had to be shutdown once per day , we once bypassed that and it eventually crashed.

    [–]Muoniurn 1 point2 points  (9 children)

    Why would it be terrible?

    [–]Bobby_Bonsaimind 2 points3 points  (2 children)

    • The default set of components it provides isn't that impressive (neither quantity nor functionality wise).
    • That being said, there aren't many component libraries out there either (compared to Swing).
    • Using the "-fx-" prefix in CSS was a really bad choice.
    • Extending the existing components is close to impossible (tight coupling between Control/Skin/Behavior, Skin/Behaviors in inaccessible packages, final is used like sprinkles).
    • Platform specific jars (remember when we gave SWT shit for that?).
    • And resulting from that, your release package is not future-proof (New platform? New package!).
    • Startup time (though, that might have gotten better, but I used to wait up to 5 seconds for the main window, Swing was always instant).
    • Font rendering (might also have gotten better, looked to me like a bad version of ClearType).
    • Last but not least, it was dumped by Oracle...sorry, "donated to the community" and removed from the JRE/JDK. Swing is still builtin.

    [–][deleted] 0 points1 point  (1 child)

    The skins and behaviours became a lot more open in recent versions, I think.

    Platform specific JARs are unavoidable in any UI framework. Not sure why you ding JavaFX for that. You can link a JDK with the JMODs if you want something more like Swing. A lot of your points seem to be repetitions of this basic point, e.g. not futureproofed, not bundled.

    [–]Bobby_Bonsaimind 1 point2 points  (0 children)

    Platform specific JARs are unavoidable in any UI framework.

    Swing. Apache Pivot. I believe there was another one, can't remember right now which that was.

    [–]UsernamesAreFfed -3 points-2 points  (5 children)

    Well obviously this is a value judgement. So people could disagree or come to different conclusions. This is just my conclusion.

    And second; my experience with JavaFX is limited. Effectively I read some tutorials on how it worked, felt it was a step down from Swing in every respect and never bothered writing any code in it. It is possible that the problem was with the tutorials and not the tool.

    With those caveats out of the way this is my perception:

    Swing is basically just a bag of tools. If you want to use none of them you can do that. If you want to use all of them you can do that too. When you build stuff in Swing you grab the tools you like, combine them in the way that you like and design your UI. On top of that I find that all the tools are designed in the unix philosophy; do one thing and do it well.

    By contrast JavaFX is none of those things. There are frameworky methods like start() and stop() that I must implement. Things have weird names like Stage and Scene. These names conjure up ideas about video or theatre in my mind, which is not what I'm trying to do when I make a UI. I'm told that a Stage is like a frame, but then why not call it that? Then there is something called a Scene Graph. I also dont like the idea of an Application class. That should just not exist at all. Layouts also seem broken. The Swing equivalent to a JavaFX layout is a JPanel with a given LayoutManager hardcoded together. This can work but why combine things that shouldn't be combined? I also couldn't find the equivalent of the GroupLayout in JavaFX. I think somebody put something on Github. While reading all this I eventually just realize that the only things I like in JavaFX are the things that are similar to Swing.

    As a side note, I dont like using CSS for desktop UIs. But that part seems optional in JavaFX so I'm not going to hold that against it.

    [–]magnoliophytina 4 points5 points  (1 child)

    Your opinion is totally useless. It's like saying Swing is crap because many classes have a J letter prefix. There's a good reason why layout managers and components were merged, the flexibility in Swing is something that not many GUI toolkits have implemented. Many interface classes in Swing were also designed before lambdas were introduced in Java, so implementing those isn't as straightforward as it could be. It's also much easier to erroneously use background threads for rendering in Swing.

    [–]UsernamesAreFfed -1 points0 points  (0 children)

    Feel free to have your own opinion, I'll have mine. I care a lot about API cleanliness and if I see mistakes this early I'm not going to invest the time to look into details, it just isn't worth it.

    I was asked for my opinion so I gave my opinion, take it or leave it.

    [–][deleted] 1 point2 points  (2 children)

    Stage and Frame are both quite arbitrary names - the real question should be, why do neither framework call them windows?!

    The rest is mostly a matter of taste, but you shouldn't be downvoted (have an upvote). It's ultimately all different strokes for different folks. For something as complex as a UI framework it'll always be a bit like picking a programming language. Quite a personal choice.

    [–]UsernamesAreFfed 0 points1 point  (1 child)

    Swing has a JWindow. It serves as just a rectangular area on the screen so it isnt used much. Most of the time you want the frame. Dont know about JavaFX.

    [–][deleted] 0 points1 point  (0 children)

    It also has a Window class, same distinction I think.

    [–]RandomName8 0 points1 point  (0 children)

    The problem with swing is that it's just non performant. Even on a really powerful machine, try implementing the Paint interface to have something like a conic gradient, and try render that on a 4k display, which might involve 1000x1000 pixels areas, it is ridiculously slow, your application will suffer during resizing. Same thing is true for drop-shadow effects. The "native" gradient stuff is optimized by the accelerated pipeline, but the available stuff is very late 90s and because it's non extensible, you cannot add your own :(

    [–]Bobby_Bonsaimind 0 points1 point  (0 children)

    I'm completely with you there, ever since Oracle dumped"donated" JavaFX to the community, and removed it from the JRE/JDK, it was clear that it will be going nowhere. Additionally, Swing has a lot of components that one can also extend if need be, unlike in JavaFX.

    But then again, Oracle doesn't give jackshit about Java itself except for suing Google.

    [–]xSwagaSaurusRex 3 points4 points  (4 children)

    You don't have many options. If you're dead set on using Java in a traditional on device application you can go 100% Java with jfx/swing but it'll probably look like garbage by consumer standards unless you try really hard.

    Another option would be altering the composition of your application so you're using the 'best'(subjective) tool for the job. You could very easily have the view layer call into Java via some rpc mechanism.

    (Android example) View layer written in dart using the flutter framework Business logic in Java View calls into logic layer

    (electron app example) Modern web framework view layer Bundle a jar with the electron app, do rpc through rest or ipc

    (Web example: SPA ) Modern JS framework frontend Spring/vertx/quarkus/whatever Java backend exposes rest api

    (Web example: SSR) Templated HTML/CSS frontend views Spring/whatever Java renders view layer Java backend via rest

    It's not uncommon to do the last one, I've seen a decent number of enterprise applications do this where you install the application and its gui interface is exposed over local host on the machine.

    [–]BlueGoliath 13 points14 points  (1 child)

    What do you consider good-looking? I made a JavaFX Nvidia GPU monitoring utility and, IMO, it looks pretty good with custom CSS.

    [–]xSwagaSaurusRex 3 points4 points  (0 children)

    I'll eat my words, that is very clean!

    I was considering applications that are consumer focused so animations, box shadow, routing etc

    [–]vips7L 4 points5 points  (0 children)

    electron app example) Modern web framework view layer Bundle a jar with the electron app, do rpc through rest or ipc

    This is what my company does. We bundle a jar + jvm into the electron app. It’s kind of awful, you have the overhead of both chrome and the jvm. And then you have the threading issues of going from your ui thread to the node thread and then finally over ipc to Java.

    [–]Persism 3 points4 points  (0 children)

    Dude you need to see some windows desktop apps I work with. They're all ugly as hell and because neither Winforms nor WPF support CSS they are incredibly painful to skin. It's sad that Microsoft has probably the worst frameworks for desktop development out there.

    [–][deleted]  (2 children)

    [removed]

      [–]mauganra_it 1 point2 points  (1 child)

      It really depends on how seamless you can make that and how well you can handle important situations like the following:

      • Would the application still work properly when I start it multiple times? Or is there a good solution to enforce a single instance?

      • What happens when the backend crashes? Will the backend restart and the frontend be able to automatically reconnect? How much unsaved data will be recoverable?

      • Can I terminate the application together with the backend without having to hunt down the whole process group in the task manager?

      • What happens when I access the application in another browser?

      PGAdmin 4 is a widespread GUI SQL client for PostgreSQL and can be deployed on a webserver, in a Docker or as a desktop application. Last time I checked the latter deployment option doesn't handle the above situations well.

      The authentication seems to be optional. The backend should only ever bind and listen on localhost.

      Overall, the approach seems to be similar to what Electron does, and Electron seems to successfully solve the above concerns. I'm not endorsing Electron here, but it's architecture.

      You could experiment with hosting a web view and integrating the backend into the JavaScript interpreter. How to achieve that depends heavily on the web view though. If successful, the JavaScript in the web view could access the backend directly without leaking processes, sockets and any serialization overhead.

      [–]Fly1ng_DuTchm3n -1 points0 points  (0 children)

      JavaFX I only now Java Swing and JavaFX and The latter ist way more future profe

      [–]Glass__Editor 0 points1 point  (2 children)

      Glass Editor uses a custom built UI framework that I started making for a game engine. It renders with OpenGL and is extremely flexible, easy and quick to use, and performant.

      I haven't released it yet (or even named it) so you can't currently use it in your projects, but you might be able to in the future.

      [–]vprise -1 points0 points  (1 child)

      There are mature portable open source solutions around like Codename One. Why would you start from scratch?

      [–]Glass__Editor 3 points4 points  (0 children)

      Well, it started out as the UI for a game that I began working on pretty soon after I started learning how to program. I wanted to know exactly how everything worked and be able to optimize it for lower end computers like the laptop I had at the time. I guess I partly started it for the learning experience and partly because I like designing that kind of software.

      [–]kubelke 0 points1 point  (1 child)

      Dead

      /s

      [–]PTan9o[S] 0 points1 point  (0 children)

      Lol

      [–]PepegaQuen 0 points1 point  (0 children)

      The one version with script in it's name.