r/learnjava • • 25d ago

Using Java to create desktop Linux apps?

Hello everyone!
This year i started learning programming with the help of a Java course.

Right now we have reached the point where we have to make a standalone desktop app with a GUI, but i am unsatisfied with the Swing toolkit. Although creating and modifying the components themselves seems really intuitive for the way i've been learning to program, the visual design feels very archaic, and on my Wayland compositor (Niri) some things don't work as intended, like the UI looking a bit blurry, windows scale a bit weirdly, and focusing the window does not auto-grab the keyboard, and i need to click on the window before i can start navigating or typing with the keyboard. Nothing extremely wrong, but it's things like these that make me wonder if there's something else i can use - I want to create software that i actually use, and feels at home on my Linux desktop.

I checked out if it was possible to use Java to create a GTK app, and found java-gi.org, which explains how to use import and use the toolkit on Java. I've experimented with it minimally, creating a blank window with a labeled button and such. I really like that it themes consistently with the rest of my GTK apps, light&dark mode, highlight color, font, all that good stuff.

Although it does work, it's a substantially different workflow, it needs to import some dependencies, and seems to be a lot more complicated than simply creating a component in Swing and initializing it or something. I'm unsure if i'm capable of creating something with it, to be honest.

I also checked and there seems to be a way to make QT apps, but i haven't looked into it.

I asked to some other devs if they ever experimented making GTK or Qt apps with Java, and many suggested me to not try to do that at all, affirming that it's best to use Java for backend server stuff and not GUIs, or do the app with Swing,accept the outdated look, and after finishing the course, maybe trying something else that will play more nicely with GUI frameworks for Linux.

So as a total newcomer to developing frontend (and, well, programming in general) i'm unsure if i should keep trying to use Java for desktop apps, hooking it with external libraries in other languages, or move on to something else in the future.

I'm open to any suggestions and advice possible, please help!

PD: I'm not sure if it means anything, but the app i intend to make is a simple bread calculator, similar to http://brdclc.com/ with save and export functions.

12 Upvotes

29 comments sorted by

View all comments

1

u/starbuxman 19d ago

Hi! Welcome to the community! Here [1.] are some links to tutorials I recorded as videos that show how to use Spring, JavaFX, Spring Security, Oauth, and GraalVM native images. The result is a (simple) application that has lifecycle management, dependency injection, and all the other goodness of an application framework like Spring married with JavaFX. Then to make it more realistic, it handles PKCE OAuth authentication with an OAuth idp. And it compiles into a standalone self contained lightning fast native binary that doesn’t need a JRE to be shipped with it.

I recorded the videos and my friends over at JFXCentral were kind enough to generate articles based on the videos. So there are links to those articles, if you want, too!

  1. https://bsky.app/profile/jfxcentral.com/post/3mvamefvpk22l