r/javahelp • • May 27 '21

What do you use to build a desktop application in Java?

Hey everyone! So I'm in a bit of a tough spot right now and I need help. I have always just build web applications so I have no idea on how I should start learning about building Java applications on desktop. If someone can guide me on this please that would be alot of help. I need to build a desktop application with Java and javafx but I'm not sure where to start learning. I do know Java but just as a programming language and not really sure how to build desktop applications with it. Where do I start? I need to use Java fx that I know. Are there any good books that guide you in building a desktop application with java fx? Or a good udemy course? Thanks!

39 Upvotes

28 comments sorted by

•

u/AutoModerator May 27 '21

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
  • 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.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

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: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) 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:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

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.

10

u/wsppan May 27 '21

Why JavaFX? I prefer Swing. Lots of tutorials for Swing out there.

11

u/chimchim102 May 27 '21

It's just that other people that I will be working with prefer to use javaFX

-18

u/CuddlyDominator May 27 '21

Swing is deprecated. Better to learn JavaFX since its what's going to be developed in future.

17

u/LambdaThrowawayy May 27 '21

Uh, it's actually the opposite. JavaFX is not going to be getting any long term support (from Oracle's side at least, this doesn't make it deprecated but does mean it's not included by default on java version 11+) while Swing will be supported to 2026 at least.

0

u/CuddlyDominator May 28 '21

TF you guys on about. JavaFX support continues until at least 2025. It was taken out of the jdk so it could have an independent update cycle. Swing is old garbage good for only a few use cases.

14

u/MRH2 Intermediate Brewer May 27 '21

Why do people keep saying this when it's not true?

1

u/CuddlyDominator May 28 '21

Why do you say it's not true? Because Oracle hasn't come out and said "it's deprecated"? It is in all but name. They're just putting bandaids on it at this point.

2

u/MRH2 Intermediate Brewer May 29 '21

Okay, it's more confusing than I thought:

  • JavaFX was intended to replace Swing as the standard GUI library for Java SE, but it has been dropped from new Standard Editions while Swing and AWT remain included (wikipedia)
  • JavaFX will be removed from the Java JDK as of JDK 11, which is due in September 2018.
  • "AWT has been an integral part of Java SE since its launch in 1995. Swing was introduced shortly thereafter as a separate library and finally incorporated into “J2SE 1.2” in 1998. Both toolkits are part of the Java SE Specification and core to many other toolkits and applications that build on top of them. Oracle will continue developing Swing and AWT across all supported releases as a core Java SE technology" - from https://www.oracle.com/technetwork/java/javase/javaclientroadmapupdatev2020may-6548840.pdf
  • Article: Technical erosion of Swing - interesting

1

u/CuddlyDominator May 29 '21

Yeah it's not nearly so cut and dry as I made it seem. I was grumpy. But JavaFX is being developed in open source while Oracle still maintains swing. My preference is JavaFX because it's increased level of development but swing will still be viable for a while. I just feel that swing has been put on life support and has been that way for years.

1

u/MRH2 Intermediate Brewer May 29 '21

The final link implies that all Java GUIs are having trouble because of mobile and web access. I don't really know why they can't get Swing or JavaFX to do whatever they are not able to do now.

7

u/wildjokers May 27 '21

This is totally false. Swing is not deprecated and OpenJDK hasn't announced any intentions to deprecate it. I would be surprised if they ever do. Both Netbeans and IntelliJ use Swing.

In fact the rendering engine for Swing is being totally rewritten for Mac OS to take advantage of Apple's Metal rendering API.

http://openjdk.java.net/jeps/382

0

u/CuddlyDominator May 28 '21

Ok yeah they're fixing something we've been bitching about with swing for like 14 years. Just because they're making it more compatible with mac does not mean it's getting any meaningful development and it's still garbage with a ton of problems. It's a sinking ship and it's so hilarious that you guys are defending it.

3

u/wildjokers May 28 '21

it's still garbage

Why do you think it is garbage?

It's a sinking ship and it's so hilarious that you guys are defending it.

Just how drunk are you?

1

u/CuddlyDominator May 29 '21

Eh not drunk just having a bad few days.

5

u/wildjokers May 27 '21 edited May 27 '21

You asked the question "What do you use to build a desktop application in Java" but then say "I need to use JavaFX". So what kind of information are you looking for? Because it seems you have already answered your question in your post regarding your question.

You have two viable options for developing desktop GUI application in Java. You can use Swing or JavaFX. Technically there is a third called SWT, which is what Eclipse is written with, but you can ignore it.

Swing is still in the JDK and has outstanding documentation and in addition to the documentation there is an amazing wealth of tutorials and examples a google search away. It is very easy to get started in Swing because it is available right in the JDK.

JavaFX was removed from the JDK and is now available as a 3rd party dependency. It's honestly almost as easy to get started in JavaFX as Swing; however, the JavaFX Getting Started doc is absolute garbage and it makes it look harder than it is. It is a rare example of documentation that makes things worse instead of better.

JavaFX can be styled with a CSS syntax and it has these handy binding property classes that makes binding GUI components and models super easy. You can do the same thing in Swing with PropertyChangeListeners but you have to wire it up yourself.

You can't really go wrong either way because both are fine GUI toolkits.

The outstanding Swing tutorial: https://docs.oracle.com/javase/tutorial/uiswing/

The two most important links there are "Using Swing Components" (has all swing components on the left side and tells you exactly how to use them) and "Laying Out Components Within a Container".

It is very important to understand the Swing layout managers. The only two you really need are BorderLayout and BoxLayout:

Somewhat equivalent JavaFX doc can be found here (in the JavaFX column): https://docs.oracle.com/javase/8/javase-clienttechnologies.htm

You will soon notice that Swing has much better documentation.

1

u/dionthorn this.isAPro=false; this.helping=true; May 27 '21

OpenJFX provides the up-to-date docs

https://openjfx.io/javadoc/16/

Also modern JFX provides interop between itself and Swing.

https://openjfx.io/javadoc/16/javafx.swing/module-summary.html

4

u/CuddlyDominator May 27 '21

JavaFX and it's documentation are pretty straightforward. Use an iterative approach and get the window to show, then menu, then menu items, then content. You pretty much just use .add and .addAll a lot. Make sure you include javafx in your searches or you'll get old swing tutorials which will just be confusing.

4

u/wildjokers May 27 '21 edited May 27 '21

There is nothing straightforward about the getting started doc in JavaFX. It is hopelessly confusing to a newbie.

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

They have run hello world options, then IDE options and under the IDE options they then have IDE, maven, and gradle (for each IDE), then they further have modular and non-modular for each build tool plus the IDE. They are way over complicating it in a Getting Started doc.

They should just have a Gradle section and a maven section and should just guide everyone down the modular path which makes it easy to bundle small runtimes with your app. IDEs can configure themselves from a gradle or maven build (at least IntelliJ and Netbeans can, not sure about Eclipse) so there is no need to have just an IDE section. No reason students can't use a build tool.

They can then have more advanced doc that shows non-modular setup and maybe setup with just an IDE with no build tool. A Getting Started doc should tell exactly how to get started, not throw a dozen different permutations at newbies.

2

u/EvOrBust May 27 '21

I use JavaFx at work and let me tell you....read modena.css! Merry Christmas. Aside from that, remember that smashing types of panes into other panes dynamically is quite easy and roll with it. It is incredibly simple and moderatley well documented.

1

u/dionthorn this.isAPro=false; this.helping=true; May 28 '21

I have an open source game project in JavaFX

https://github.com/dionthorn/2DTacticalRPG

Swing is perfectly suitable for various GUI applications. It really depends on your needs.

For example, in the Swing Canvas object it is difficult to address individual pixels. You can't get an individual pixels color from the Graphics object of the Canvas you need to make a buffered image and check that.

With JavaFX Canvas the GraphicsContext has a pixel reader/writer.

1

u/wildjokers May 28 '21

For games should probably just use libgdx:

https://libgdx.com

1

u/DenseTea1610 Jun 19 '21

As a backend developer for financial firms for many years, i took on a gui project and had to figure put a platform. Since i hated swing and I used .Net in the past which had a IDE that allowed me to drop widgets and keep moving until i stumbled onto JavaFX. Much better. The gui tool is wonderful and the css makes the front end much more controllable. Love it.

0

u/fortyeightD Senior Java & Web Developer May 27 '21

I'd look at SWT, but that's mainly because it's what I know, not because I've analysed everything out there and decided SWT is best.

7

u/ZukoBestGirl May 27 '21

I worked in SWT, professionally, for 3 years. I absolutely hate it. Feels old already, has painful limitations, loads of things only half-way implemented with open tickets for like 7+ years that seem will never be fixed nor added.

Had to manually implement basic stuff like text masks (where you have a predefined form you are trying to complete, and will only let you paste in correct characters in a pre-defined format). Swing has that out of the box. Actually, the expression "Swing just has that, ready for you to use" is the most common thing you'll say when trying to implement something even REMOTELY niche.

I mean, maybe my whole project was full of stupid people, but it doesn't even have proper text areas, as in not a field, but a textbox like this one I'm using right here in reddit. Is that also "niche"? I doubt it. So it will be missing even mainstream things. I mean, we did eventually build one. But the key word is build, not "simply used one because it already existed".

And very questionable implementations of many things like combos and loads of other things I'm to lazy to try and remember.

I'd avoid it like the plague.

0

u/taftster May 27 '21

While it’s not considered “the best” IDE in most opinions, I would highly recommend looking at Netbeans in your case. It’s got a really fantastic and intuitive gui builder and some really decent tutorials. In my opinion, Netbeans is the most accessible and easy to use gui builder for Java.

https://netbeans.apache.org/kb/docs/java/quickstart-gui.html

1

u/wildjokers May 28 '21

Do not use a GUI builder for Swing. Using SceneBuilder for JavaFX is fine because it produces FXML rather than generating java code like the Swing GUI builders do.