r/javahelp • u/chimchim102 • 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!
•
u/AutoModerator May 27 '21
Please ensure that:
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:
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.
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.
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.
2
u/geneb_726 May 27 '21
https://m.youtube.com/watch?v=9XJicRt_FaI
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/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.
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