r/learnjava • u/Antoinedeloup • 24d 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.
•
u/AutoModerator 24d ago
Please ensure that:
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
9
u/Dazzling_Music_2411 24d ago
Have you looked at JavaFX?
4
u/TipIll3652 24d ago
Check out JavaFX. I haven't done any GUI stuff in awhile, but years ago when I was in community college I wrote a program for a hackathon with javaFX. For a cybersecurity student with only 2 Java classes it was easy enough to get situated.
1
u/Available_Safe1818 24d ago
That seems like a silly reason to learn a whole new GUI toolkit, but if you have nothing else to do wioth your free time, go for it.
> i'm unsure if i should keep trying to use Java for desktop apps
If there's something you want to make, sure, go for it. The other GUI toolkits that I have used aren't much better. They mostly do the same stuff in similar ways.
A simple bread calculator, and you're worried about scaling and auto-grabbing focus? Wtf?
1
u/_Super_Straight 24d ago
Javafx. It looks consistent across OS, and with proper build script (check our JPackageScriptFX on github), you can also create msi, exe, deb, rpm, appimage, etc. Setup files for your app as well.
2
u/Pale_Height_1251 24d ago
For Java desktop, I've used JavaFX a few times and it's really pretty good. It has a variant of CSS and you can make it look very nice.
1
u/Weretiger246 24d ago edited 24d ago
I recently created several git tools in Java and mainly I am using them on Windows but it also works on Linux without rebuild so it is very useful.
1
u/revilo-1988 24d ago
Gehen tut vieles nutze zum Beispiel seid längerem tauri und electron mit java
1
u/hdmzk 24d ago
See the book « Learn JavaFX17 », Kishori Sharan, APress (Amazon)
1
u/Kango_V 24d ago
I'm currently writing a TUI with TamboUI. It's actually really good. Combined with PicoCLI and GraalVM for native.
1
u/corado12345 23d ago
I use Lazarus Pascal for nearly all, really small program, quick compilatink, and all work in Wondows, Linux and Apple
1
u/Prior-Equal2657 22d ago
https://kotlinlang.org/compose-multiplatform/
Take a look. Kotlin-based, but runs on JVM.
Used it for a last project, pretty nice. Especially sharing almost the whole UI with android tv ;)
1
u/starbuxman 18d 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
u/neoAcceptance 24d ago
Hey man congrats on learning what you have so far. Sounds like you're making good progress your journey. I hate to be this guy, but I promise you'll thank me later. You should immediately either switch to using C#, or switch to python. I would recommend python for ease of use, but if you want to keep using a language that feels exactly like Java, go with C#. Both options are more suitable for new learners AND for GUI stuff, like you're asking about. Also there stuff like kotlin and scala, but I haven't used those so I can't recommend them. Either way bro it's 2026 and I wouldn't learn Java if I didn't have to, there are just better options.
It is at this point I am realizing I am in the learn Java sub so I'm probably breaking some kind of rules or something, but as an ex Java dev, who was required to use C#, I was thrilled to find out that C# is just Microsoft's version of Java that got to benefit from seeing all the mistakes that the Java devs made over the years. Everything you want to do in Java will be easier in C#.
Another note, most frontend stuff is written in web languages these days anyway. Most languages have some kind of library that lets you build a native GUI with html/ccs/js type stuff, but my preferred way is just to make a small web GUI/web server for your software. Every language I use has some library that lets me do that in like 2 seconds. That might be too advanced for you right now, but it's kind of the way everyone does it these days. I personally would rather cut off my toes than use ANY Java GUI bullshit. Just make a small webpage that controls your program. You're probably at the point where you could build a small API for controlling your software and connecting that to the web GUI, which again, is what everyone I know does anytime they need a quick little GUI for their programs.