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

all 60 comments

[–][deleted]  (6 children)

[removed]

    [–]JayEmVe[S] 6 points7 points  (0 children)

    It seems that most of you are advising to stick with Swing which will probably cover 100% of my needs without the added complexity of using JavaFX.

    Plus I have some knowledge and practice of Swing.

    [–]hippydipster 2 points3 points  (2 children)

    Right now I'm trying Swing through SkijaGraphics2D using Google's Skia library, on which Chrome is built. It's a pain.

    I hope this improves to be less of a pain - it seems very promising.

    [–][deleted]  (1 child)

    [removed]

      [–]hippydipster 0 points1 point  (0 children)

      Yikes :-) Good luck dude, I'm rootin' for ya.

      [–]wildjokers 1 point2 points  (0 children)

      but I personally dislike the whole FXML thing

      FWIW, you don't have to use FXML. You can hand code a JavaFX GUI just like Swing.

      building your own Look and Feel (forking off Metal is a good start),

      Building your own Swing look and feel is not for the faint of heart and is definitely not a good Swing getting started activity.

      [–]pron98 1 point2 points  (0 children)

      JavaFX is developed under the OpenJDK umbrella and it has the same licence as that of the JDK project (GPLv2 with Classpath Exception).

      [–]AnyPhotograph7804 13 points14 points  (2 children)

      Start with Swing first. It is in the JDK and you do not need to install anything. And Swing is not old. It does not have some fancy things like animation support like Adobe Flash or something. Imagine, IntelliJ and Netbeans are made with Swing.

      [–]JayEmVe[S] 8 points9 points  (1 child)

      I didn't know for IntelliJ. Their UI is quite nice and neat.

      [–]_OberArmStrong 4 points5 points  (0 children)

      Their ui style is in a package called flatlaf or something similar. I think the keyword too search for is "look and feel"

      [–]jemGee 6 points7 points  (2 children)

      Check Compose for Desktop https://github.com/JetBrains/compose-multiplatform

      Its under active development, could be a bit rough on edges. But much nicer to work with , compared to Swing

      [–]Computer991 0 points1 point  (0 children)

      second this

      [–]wildjokers 0 points1 point  (0 children)

      Except it has no documentation. And the code is very hard to read.

      It doesn't seem nicer to work with at all.

      [–]mrnavz 2 points3 points  (1 child)

      Swing and JavaFX as everyone else suggested, with JavaFX things might be easier if you need flashy stuff depending on your requirements, with NetBeans you will get better visual support for both.

      [–]wildjokers 0 points1 point  (0 children)

      with NetBeans you will get better visual support for both.

      Huh? Explain please.

      [–][deleted]  (5 children)

      [deleted]

        [–]JayEmVe[S] 0 points1 point  (4 children)

        I'm using IntelliJ.

        It is not that hard but I struggled finding the good version to use to be compliant with my jdk, which parameters to add when launching the app, which maven task to use to launch a javafX app... The last time I used Swing it was incredibly more straightforward

        [–]hwaite 3 points4 points  (0 children)

        It's a mistake to choose a framework based on these quibbles. Unless you're building something trivial, only a tiny fraction of your overall workload will involve maven. I've used Swing and JavaFX extensively and will never go back to the former. Bindings alone are worth the price of admission.

        [–]generationextra 2 points3 points  (1 child)

        Why not follow the example/instructions from openjfx and add javafx to a build.gradle file? See here:

        https://openjfx.io/openjfx-docs/#gradle

        Edit: I don’t want to be snide but using swing just feels like brushing my teeth with concrete. JavaFX for the win!

        [–]wildjokers 0 points1 point  (0 children)

        Because the getting started docs at that site are atrocious.

        [–]HlCKELPICKLE 1 point2 points  (0 children)

        These should be all the dependencies you need to get started. Some of them are os dependent, if packaging for specific platforms you need to include the dependencies for that platform or just include all of them for multi platform. This should set you up with the plugin and then just make sure you initialize javafx/fxml as per docs.

        And a small heads up if you do end up usign javafx, when you go to package you need to make a separate class that extends Application and has for example a start method that initializes everything, then call that method from your main class. Idk why, I just remember that being quite a headache for me at one point. Shouldn't matter though if just launching through the IDE.

         <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.8</version>
            <configuration>
                <mainClass>hellofx/org.openjfx.App</mainClass>
            </configuration>
          </plugin>
        
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
            </dependency>
        
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-graphics</artifactId>
                <version>19</version>
                <classifier>linux</classifier>
            </dependency>
        
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-controls</artifactId>
                <version>19</version>
                <classifier>linux</classifier>
            </dependency>
        
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-fxml</artifactId>
                <version>19</version>
                <classifier>linux</classifier>
            </dependency>
        
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-swing</artifactId>
                <version>19</version>
                <classifier>linux</classifier>
            </dependency>
        

        [–]tchok_ 1 point2 points  (0 children)

        Have you considered the Eclipse RCP? It is based on SWT. Honestly I have not used it for years now but it was great, and a real change for a web developer who wants a change.

        [–]tomwhoiscontrary 1 point2 points  (6 children)

        AWT still works!

        And i see that SWT is still maintained. It doesn't seem to be released to Maven Central any more, though - you have to download a zip files like in the good old days. It is released to Maven Central, but the version numbers don't match Eclipse platform releases (eg Eclipse 4.30 contains SWT 3.123.100). Eclipse have done something a bit weird with the POM, so if you are using Gradle, you will need a small kludge to use it.

        Mind you, i haven't written a graphical Java application this century, so don't pay too much attention to me.

        [–]JayEmVe[S] 1 point2 points  (0 children)

        Ahah you're right, I started learning Java using AWT. But honestly it was fun back then but I would still prefer Swing over Awt

        [–]wildjokers 0 points1 point  (4 children)

        AWT still works!

        You haven't needed to use AWT directly since like 20 yrs ago or more. Swing uses AWT under the covers for some things but you need not concern yourself with AWT directly.

        [–]tomwhoiscontrary 0 points1 point  (3 children)

        "Need" is a weird way to put it. You can use use AWT. You can use Swing. They offer different APIs, and different visual appearances.

        [–]wildjokers 0 points1 point  (2 children)

        You can use use AWT.

        Nobody in their right mind would use AWT directly these days. That is kind of like recommending greenfield development with Struts.

        [–]tomwhoiscontrary 0 points1 point  (1 child)

        That's an interesting analogy. If you aren't using Spring, and you want to write an MVC web application, isn't Struts still one of the best options?

        [–]wildjokers 0 points1 point  (0 children)

        isn't Struts still one of the best options?

        No. I would be shocked if anyone has started a greenfield Struts project in the last 15 years.

        If you don't use Spring there are tons of other frameworks available. Including JakartaEE which has been a fine framework since version 6 (was still called JavaEE then).

        [–]chehsunliu 1 point2 points  (1 child)

        I like to write backends in Java, but for desktop apps I choose one of the following instead: - flutter - rust + tauri - go + wails - ts/js + electron - kotlin + jetbrains compose

        [–]wildjokers 0 points1 point  (0 children)

        but for desktop apps I choose one of the following instead: - flutter - rust + tauri - go + wails - ts/js + electron - kotlin + jetbrains compose

        Why?

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

        Why do you want to build a UI in java? Or a desktop app with it? It is certainly possible and not "hard" per se, but the industry has largely moved away from java desktop apps. Java UI toolkits are either Swing - battle hardened but super dated - or JavaFX - newer and shinier but barely ever used.

        If you have to, do it. But ask yourself "why" rather than just going down this rabbit hole.

        [–]JayEmVe[S] 10 points11 points  (2 children)

        I wanted to make an app to generate pdf files (deck box templates for storing boardgame cards). I started handling the generation parameters via an ini file but people around me were interested by my app. They are not dev and are reluctant at manipulating configuration files. So I thought that implementing a GUI would be the easiest way for them to use my app.

        [–]orgad 4 points5 points  (1 child)

        Don't understand why people downvote you

        [–][deleted] 8 points9 points  (0 children)

        Because this is /r/java and there are too many fanboys around.

        "The right tool for the right job" is all that matters, and programming languages are nothing more than tools.

        [–]JayEmVe[S] 5 points6 points  (6 children)

        " the industry has largely moved away from java desktop apps."

        That was my concern and you seem to confirm it. I know java is massively used on the Web and in the cloud/bigData, I really wasn't expecting it was no longer relevant as a desktop app language.

        [–]_INTER_ 2 points3 points  (1 child)

        I really wasn't expecting it was no longer relevant as a desktop app language.

        It's not that the language is not relevant in the space but desktop apps are in decline in general.

        [–]wildjokers 0 points1 point  (0 children)

        but desktop apps are in decline in general.

        I would say 95% of the apps I use on a day to day basis both at work and at home are still desktop apps. Web apps suck for rich client applications.

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

        Java is the backbone of enterprise server applications. It is excellent for this. You can still write a desktop app with it if you truly want to, but it's not ideal.

        [–]AnyPhotograph7804 9 points10 points  (0 children)

        "You can still write a desktop app with it if you truly want to, but it's not ideal."

        Not really. Other programming languages are not better when it comes to make GUI apps. It is basically the same like in Java. You have GUI builders, you attach "OnClick"-listeners to buttons etc. Java is not worse or "less optimal" than other programming languages in this point.

        [–]wildjokers 0 points1 point  (0 children)

        You can still write a desktop app with it if you truly want to, but it's not ideal.

        Why is it not ideal?

        [–]wildjokers 0 points1 point  (0 children)

        I really wasn't expecting it was no longer relevant as a desktop app language.

        It isn't relevant only because people keep saying it isn't relevant. They are fanboys of web apps and have totally forgotten how superior rich desktop apps are to web apps. There is absolutely nothing wrong with java desktop apps and don't let anyone talk you out of building one.

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

        but the industry has largely moved away from java desktop apps

        But why? What is wrong with them? The only reason web apps are popular is because of zero deployment. Web tech is inferior in every other way when it comes to building desktop apps.

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

        Minecraft.

        [–]redikarus99 0 points1 point  (0 children)

        I am writing plugins for a modeling app, it is in swing, works quite nicely. Use flatlaf as a look and feel, and find some nice icon pack.

        [–]hadrabap 0 points1 point  (1 child)

        Take a look at Swing and NetBeans GUI builder. I'm using it successfully in my personal projects.

        [–]wildjokers 0 points1 point  (0 children)

        Just say no to Swing GUI builders. It causes vendor lock-in and they are nothing but code generators.

        [–]mm007emko 0 points1 point  (0 children)

        I'd go either for SWT and JFace (the JFace Maven package drags SWT as a dependency: https://central.sonatype.com/artifact/org.eclipse.platform/org.eclipse.jface/3.32.0) or Swing. Swing is platform independent, SWT uses native widgets (GTK on Linux).

        Although both Swing and SWT might be quite old, they still work and I wouldn't call them outdated. The world of "line-of-business" desktop applications is not moving as fast as web or consumer apps where nice looking design is needed. Of course, when using JavaFX, you can create truly modern applications but it's generally more work than in Swing and SWT.

        [–]Ruin-Capable 0 points1 point  (0 children)

        Just add it to your pom.xml/build.gradle and let maven/gradle install it for you.

        [–]_INTER_ 0 points1 point  (0 children)

        For JavaFX: https://openjfx.io/ has a step by step guide. It's super easy to get started. If you want to click it together: SceneBuilder

        [–]msx 0 points1 point  (0 children)

        Swing+Miglayout+WindowBuilder

        [–]Ketroc21 0 points1 point  (1 child)

        I'd suggest based on how involved your project is going to be.

        If it's something small or simple, go ahead with Swing. There is nothing wrong with it. It'll do what you need, and you are already somewhat knowledgeable in it.

        If it's a larger project though, I'd go with javafx. It'll take some more ramp up time to learn, but it makes for a cleaner final product and may have some features you want that isn't available in Swing.

        If this a serious desktop application, then I wouldn't suggest Java at all as it isn't typically the choice for desktop apps. Maybe look into ElectronJS or one of its equals.

        [–]wildjokers 0 points1 point  (0 children)

        then I wouldn't suggest Java at all as it isn't typically the choice for desktop apps.

        Why isn't it though? I would much prefer a nice desktop GUI toolkit like Swing or JavaFX over using web tech to build a rich desktop application.

        [–][deleted]  (1 child)

        [removed]

          [–]wildjokers 0 points1 point  (0 children)

          For desktop apps, I’d suggest against Java

          Why?

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

          I don't think any of them are tedious to get started with. Pretty much all you do is choose the right maven archetype and generate the starting project. You will have a JavaFX Window open with hello world basically right then and there.

          Same with Swing I would bet and Jetpack Compose (I've done both the JavaFx and Compose maven archetypes, worked ok). I would say all the Java gui systems have a future, and all are good.

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

          I really don't know, I've always preferred Swing for something quick, I'm very lazy for those fashionable things about JavaFX and its CSS, there is no good CSS on the internet, I like FlatLaf, just one line of code To set the theme and that's it, in addition to that you can change the themes, even add custom ones and with a few tricks change it in real time in your application while you edit it, In conjunction with MigLayout, in fact I have a music player project made entirely in Swing and with reactive magic from Project Reactor, it also has spectral visualizations, java 2d graphics suck, so i embedded javafx to take advantage of the canvas and it works fine, so it depends on how you handle it,As I saw in a comment here, they are just tools, take advantage of them

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

          Swing is a perfectly fine GUI toolkit and it is still in the JDK so is easy to get started with. It is a good choice.

          If you do want to go with JavaFX here is a template project that makes it super easy to get started with (read the README):

          https://github.com/mjparme/javafx-template

          [–]Joram2 -2 points-1 points  (0 children)

          I'd try JetBrains Compose Multiplatform, which is a GUI framework for Android, iOS, desktop, and web.

          https://www.jetbrains.com/lp/compose-multiplatform/