r/learnjava • • Nov 19 '21

what is the best way of implementing a GUI nowadays?

im in a java class and for my final i wanted to be fancy and include a GUI. ive already been experimenting with Swing, but all the stack overflow articles i see are from the early 10's and a few that are mid 10's say to not use swing as its archiac.

i would like to learn the new offerings of doing a GUI's but from what i gathered, JavaFX is already depreciated? or at least not getting support or something? not sure if i understand that right. someone please point me in the right direction though?

i have been programming using JGrasp, im not the most interested in downloading other IDE's.

48 Upvotes

20 comments sorted by

30

u/[deleted] Nov 19 '21 edited Nov 19 '21

Swing is indeed old, don’t use it for any new projects. JavaFX is not deprecated, it just is not bundled with the JRE by default anymore. You have to install it as a dependency.

It is still actively maintained, it just isn’t part of core Java anymore.

This is because IMO, to be completely honest, in the real world very few net new Java based GUI applications being made. The community is moving to electron based apps (for better or worse is debatable).

I think the JVM team saw this trend, and decided to stop bundling JavaFX into the JVM. “Why increase the binary size for something infrequently used ?” basically.

3

u/Potat_OS1 Nov 19 '21

ah i see, and what do you mean by "baking made"?

2

u/[deleted] Nov 19 '21

being made.

1

u/Potat_OS1 Nov 19 '21

ah ok, ty

11

u/cheeara Nov 19 '21

I used Swing for a Java project earlier this year and our TAs actually recommended it since it was older and there would be a lot of information on it. Me and my lab partner found it alright to use but without me basically redesigning the GUI using PNGs as buttons it was extremely ugly.

One of my friends used JavaFX and it seemed to not be as convoluted as Swing, and was a lot more aesthetically pleasing. If I'd done something differently I probably would've used JavaFX instead.

8

u/sweetno Nov 19 '21

It seems the whole industry jumped on the web interface train. Other than that, you can choose between Swing, JavaFX and SWT. SWT might be a bit too low level, but it also gives the nativest look & feel.

14

u/narlight1928 Nov 19 '21 edited Nov 19 '21

Don't use Swing it's overly complex and archaic, You will lose support for it after 1.8 is taken off LTS, and using a javax.embed or javafx.swing dependency isn't ideal. JavaFX is surprisingly fun, and straightforward. I am currently rebuilding a client's app from AWT to JavaFX. As a language JavaFX is far from deprecated, Openfx11/15 is still widely supported. It is only shipped as separate jars currently due to the swelling size of the jre and the introduction of modularity in Java 9. As they wanted to tackle java on low processing power devices (IoT) and offer encapsulation at all levels.

I would take a day and learn how to use javafx layouts, listeners and actions/events. Use of the .FXML/Controller format will drastically improve your project. It has has a moderate learning curve but extremely streamlines the process. Along with that look into the companion program JavaFX SceneBuilder 2.0 for click and drag gui generation.

edits: Java 9, FXML, SceneBuilder

3

u/[deleted] Nov 19 '21

I wouldn’t recommend TornadoFX. It’s basically unmaintained at this point. Take a look at the commit history. Development basically stopped 2 years ago.

https://github.com/edvin/tornadofx

2

u/narlight1928 Nov 19 '21

Thank you for pointing this out! I'll take the suggestion out of my comment. Still an extremely fun language.

1

u/[deleted] Nov 19 '21

I’m not exactly saying to not use it at all (I still do for a personal project and have no plans to migrate my work to electron), just not for large scale business critical applications. For toy projects, it matters a whole lot less how active the developers are.

Take all opinions on Reddit with a grain of salt! Maybe I’m a retard giving shitty advice.

1

u/narlight1928 Nov 19 '21

For sure mate, caught me off guard it was ~deprecated haha. I've sandboxed a lot with it before in Kotlin and I think we actually pull in a few Tornado elements not found in FX, ie DateTimePicker, so that's really good to know!

3

u/[deleted] Nov 19 '21

Definitely JavaFX it's the one that's newer and is getting updated. Swing is old and it's not getting any updates as far as i know. However you still can find Swing in old code bases.

With JavaFX you can use Scene Builder too (drag/drop GUI that helps you developing the app).

2

u/BridgeBurner22 Nov 19 '21

I would also suggest JavaFX. I prefer it to Swing. A great blog for JavaFX is: https://edencoding.com/ this helped me a lot when I started with JavaFX.

2

u/i_ask_stupid_ques Nov 19 '21 edited Nov 19 '21

Can you make a web based GUI even if it runs on your local machine. Take a look at some Vaadin demos on Youtube

https://www.youtube.com/watch?v=bxy2JgqqKDU&t=358s

https://www.youtube.com/watch?v=quiQg9bgFs8&list=PLcRrh9hGNallPtT2VbUAsrWqvkQ-XE22h

2

u/FroggyWizard Nov 19 '21

I don't understand why this comment is at the bottom. Web based GUIs are absolutely the right way to go. In the actual software industry the vast majority of modern GUIs are web based.

2

u/hermitfist Nov 19 '21

Go with JavaFX as it's the newer of the two. Although you won't go wrong if you choose Swing either. As others pointed out, native Desktop development isn't really common as most businesses prefer a cross platform solution to save $$$.

Tbh, you can still make really cool things with Swing. I just made a turn-based RPG for a Java class last year with it. A lot of overriding the paintCompment method and you need to implement certain things yourself like sprite animation and player camera. In the end, no matter which you choose, it's not really a waste of time as long as you're learning something.

1

u/CorDharel Nov 19 '21

JavaFX is very easy to use imo so totally recommended. We also used it in our company.

1

u/wimdeblauwe Nov 19 '21

You might be interested in this book to get started on JavaFX: https://www.amazon.com/Definitive-Guide-Modern-Clients-JavaFX/dp/1484272676

0

u/[deleted] Nov 19 '21

[deleted]

8

u/Potat_OS1 Nov 19 '21

its a java class.

0

u/verocoder Nov 19 '21

A modern Java service with a front end will have a well defined rest api and JavaScript (or even simple html forms) that interact with it. Java UIs (or any thick client desktop app) are harder to manage in the business world than web apps with say saml integration for auth.

If you’re trying to be fancy how about a rest interface and open api/swagger docs you could show your app off with. Helluva lot quicker and something you might actually use outside of school.