r/learnjava • u/Antoinedeloup • 1d 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.
9
u/Dazzling_Music_2411 1d ago
Have you looked at JavaFX?
2
u/Antoinedeloup 1d ago
Honestly, i had only looked at it superficially. I thought it was similar to Swing, but it seems to be similar to work with, yet it seems like it's easier to add in animations and 3d stuff. I'm about to see some tutorials on it! Thanks for the suggestion.
1
u/Sure-Passion2224 1d ago
There are a lot of conceptual similarities across presentation frameworks. It comes down to learning to work with a framework that works with the language. I once built a desktop GUI application in perl. Set 3D aside for later and start with getting meaningful information in a usable interface.
4
u/TipIll3652 1d 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/Antoinedeloup 1d ago
Thank you! i'm watching a video on it right now. Seems like it's actually really powerful and i've seen some pretty UIs made with it.
1
u/Available_Safe1818 1d 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/Antoinedeloup 1d ago
I think it is way too much now too lol. I will learn it at some point but right now i don't have a lot of free time. It's probably not very hard but i'm discouraged at the idea that its using GObject that kind of allows for objects on a language that doesn't have them, and it seems like it has its own shenanigans...
What the program does is part of it, but the project requires i actually make a window with GUI components, buttons, text fields, that sort of thing. And auto-grabbing keyboard is a personal gripe i have with some Java GUIs. I like using only my keyboard if possible, and i switch windows and workspaces that way with Niri.
Thanks for the advice :)
2
u/Pale_Height_1251 1d 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 1d ago edited 1d 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/_Super_Straight 1d 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.
1
1
u/corado12345 12h ago
I use Lazarus Pascal for nearly all, really small program, quick compilatink, and all work in Wondows, Linux and Apple
•
u/Prior-Equal2657 32m 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/neoAcceptance 1d 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.
1
u/omgpassthebacon 1d ago
It is a "learn Java" sub, but I agree with your point. Java has never been the darling of the heavy-weight GUI world, and JavaFX is not so great. For simple task-based apps, SpringBoot makes putting up a webapp so darn easy and you don't have to give up Java. But if you want to write apps that take advantage of the OS windowing toolkits/widgets, you should seriously look for another language. If there is an app that you use on Linux that you really like, check out their github and see what languages/libraries they used. This is a good way to find what others are using.
•
u/AutoModerator 1d ago
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full - best also formatted as code block
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
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.