r/programming • u/javinpaul • Sep 18 '18
JavaFX 11 is released
http://mail.openjdk.java.net/pipermail/openjfx-dev/2018-September/022475.html14
u/MrN_Nabhani Sep 18 '18 edited Sep 18 '18
Hi! Can someone tell me (in short) what is JavaFX ? Am taking Java this year and I would love to know what stuff I should know about later on, thanks in regards ^
26
u/Sigmatics Sep 18 '18
It's a cross-platform GUI library.
JavaFX is a software platform for creating and delivering desktop applications, as well as rich Internet applications (RIAs) that can run across a wide variety of devices. JavaFX is intended to replace Swing as the standard GUI library for Java SE, but both will be included for the foreseeable future.[3] JavaFX has support for desktop computers and web browsers on Microsoft Windows, Linux, and macOS.
14
u/hi_im_new_to_this Sep 18 '18
I’ve heard it’s cool. Like in a ”yeah, we all hate Java, but JavaFX is actually pretty dope” way. Can anyone elaborate?
21
Sep 18 '18
I enjoy it quite a bit. I use some bindings for Scala (ScalaFX) and it lets me make GUIs without using Java. There are also some bindings for Kotlin (TornadoFX). You can either declare the UI programmatically, using code, or do what I do and use FXML. FXML is kinda like HTML, but it lets you use a designer to more easily generate the UI. The only one I know of is Scenebuilder, which used to be owned by Oracle before Gluon took over. There aren't many libraries that work with JavaFX, but one of the ones I use is called JFoenix and it has a bunch of widgets in a material design style. Additionally, you can use CSS to style the widgets more precisely; it isn't the full CSS spec, but it contains most of what you need.
Overall, it feels like a more polished version of front-end web design, and even though it runs on the JVM, it still performs much faster than Node/Electron. And I would take any of the popular JVM languages over JavaScript in a heartbeat.
14
u/TheWheez Sep 18 '18
even though it runs on the JVM, it still performs much faster than Node/Electron
I think the JVM gets a bad wrap because of its attachment to Java. Web containers are becoming increasingly bloated and resource intensive (often not under the control of the application developer). I think JavaFX would be a breath of fresh air to come back to after web development, and I'd love to try it out if given the right opportunity
7
u/UpsetLime Sep 18 '18
It should be noted that TornadoFX still doesn't support Java 9/10/11. Hopefully that will change now with JavaFX being uncoupled.
2
Sep 19 '18
The only I really want to know but haven't seen anyone talking or real mentions about it: does it implement native widgets and integrate properly with native platform? Or is this all web technology pushed to the desktop? It seemed the later when I tried to look into scalafx some time ago. Does it finally make font rendering actually work properly or is the same bushit as swing?
3
Sep 19 '18
Does it implement native widgets and integrate properly with native platform?
No, but you can get pretty close with the default theme and styling. I haven't found any simple cross platform GUI frameworks that do this. From what I've heard, Qt is pretty close, but still has some discrepancies.
is this all web technology pushed to the desktop?
Not really, the closest you'll get to web technology is if you use FXML and CSS, but that is not a requirement. You can create a whole UI without touching either of those by creating all of the widgets and layout programmatically from the JVM language of your choice.
Does it finally make font rendering actually work properly
I haven't had many problems with rendering text, but I've found
System.setProperty("prism.lcdtext", "false");to help in some cases.2
Sep 19 '18
Thanks for the answers. Was looking into some of the websites trying to get a better picture of what the widgets and UI looks and not sure the documentation is a strong point currently. Do you find it sufficient, do you have other recommended resources to learn from?
What is the more usual or reasonable way to create those UIs, programmatically or using the FXML definitions?
I could see maybe using this to create some internal tools to help the devs and qas with some stuff they usually have to do.
4
Sep 20 '18
Official JavaFX API Docs: https://docs.oracle.com/javase/8/javafx/api/toc.htm
A third party collected a bunch of information from the internet and put it here: https://fxdocs.github.io/docs/index.html
JavaFX CSS spec: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html
My personal workflow starts by generating FXML files using SceneBuilder, then adding functionality by binding a controller class to the FXML file (I use the ScalaFX and ScalaFXML). Later, I add in in the CSS and make it look nice.
When I'm done, I use the sbt-proguard plugin for SBT in order to assemble all the classes in a single jar and minimize the file; it brings the size of the jar down from 15 or so MB to 2MB and makes it so that an end-user only needs the JRE to run it.
Ive only been using JavaFX for little while and I haven't made any commercial applications, so take my advice with a grain of salt. I would recommend trying it out on your own time before committing to using it for business.
1
Sep 20 '18
Thanks. This really helps. I'll have to take a proper look and experiment with it a little. Also my main language is scala so that's definitely the path I'll try to go with.
1
u/geordano Sep 18 '18
It's a damn good library (anecdotal from few of my friends at office who are using it for couple of FX systems), very underrated for its capabilities it seems.
-14
u/MrN_Nabhani Sep 18 '18
so is Swing like SVG in HTML.. And JavaFx a more complicated graphic library like OpenGL in C++
9
u/x86_64Ubuntu Sep 18 '18
Well, it's more similar to WPF and Adobe Flex/MXML than HTML. But it does have some similarities, for instance, your template may compile, and then blow up on you during runtime because your fxml is botched somehow.
2
u/rockum Sep 18 '18
Nope. Swing is a pretty standard GUI library with classes for buttons, menu bars, layout managers, etc. It was unique in that it encourages separating the model from the view. Also separated rendering from UI elements so there are separate renderers for each platform.
1
u/TesticularCatHat Sep 18 '18
Not at all. Swing is also a cross-platform (AFAIK) library for making GUIs.
-2
u/Jarmahent Sep 18 '18
Why not just Google it?
1
0
Sep 19 '18
[deleted]
6
1
u/Jarmahent Sep 19 '18
Except it never will be. There are way more useful and in depth resources on JavaFX compared to some random Reddit stranger giving his 1, 2 on it.
0
Sep 19 '18
[deleted]
1
u/Jarmahent Sep 19 '18
I disagree. People who want to learn something new need to learn that Googling Is usually what you want to do.
1
Sep 19 '18
I was thinking of starting a PoC with JavaFX, not knowing Java but knowing C# very well. How much better would it work out than an Electron app? I know everyone hates Electron but we've released an app with it that works pretty well. I'd seriously consider trying JavaFX though. Appreciate any feedback
7
u/greeneagle692 Sep 19 '18
i think i've posted this before, i have ported my electron app to javaFX, looks exactly the same. difference here is its less bloated than the JS ecosystem, faster, you have strong typing out of the box, and you don't have to worry as much about the security holes of having a web app have system access (XSS bugs and such). The part about whether you like it or not comes down to if you like strongly typed languages or something weakly typed like JS. I've spent enough time in JS that I absolutely abhor working on it... currently its my job to work in vanilla ES5 Q_Q.
The tipping point on why i flipped from Electron to JavaFX was because after a few months of not working on it half the libraries i was using completely changed their APIs and the typescript definition files were only partially complete. Made it super frustrating to work with when its a mystery whats in an object and constantly editing definition files.
2
Sep 19 '18
Thanks! I hear you on ES5, I still support IE and it makes me want to smash baby kittens. Appreciate the insight
1
u/xlzqwerty1 Sep 19 '18
May I ask what the memory usage was like with your Electron app compared with a JavaFX app? I'm just curious about anecdotal results, as I'm in the process of picking a good cross-platform GUI library to work with.
3
u/greeneagle692 Sep 19 '18 edited Sep 19 '18
well can't say since i don't have the electron version anymore, but without any optimization or VM options, garbage collector kept it around 200mb-300mb. Most of the memory footprint TornadoFX related, managing views and partials. My code's memory usage was significantly less like around 50mb at the heaviest parts.
EDIT: Ofc your mileage may vary, I haven't finished said app but if your views are more intense you'll likely use more ram. I haven't used vanilla javafx so not sure how much of that ram usage is due to inefficiencies of the wrapper vs javafx. Anywho, its down to preference imo, I'm sure you can optimize ram usage for electron if you spent enough time on it as much as JVM (see vscode). I just find it easier and cleaner to work with the JVM
0
Sep 19 '18
[deleted]
1
u/greeneagle692 Sep 19 '18
Havent tried programming purely in Java/JavaFX/FXML. programming in JavaFX is too "low level" for me, i wanted to get something up quickly which is why i used TornadoFX. Griffon is another good wrapper that works with Java Groovy and Kotlin. TornadoFX gives you object lifecycle management/dependency injection like spring does, some premade elements, and a couple other utilities. Also, i code the views using kotlin builders rather than FXML, you can use either though
-1
u/FierceDeity_ Sep 19 '18
If you know C# very well, wouldn't WPF achieve essentially the same thing?
WPF is a technology with a lot of the same design goals as JavaFX
scene graph for rendering,
backing rendering with the GPU,
using a XML-based language for the layout (XAML vs FXML)
It does differ though, for example WPF uses ViewModels and FXML uses Controllers - MVVM vs MVC
9
u/tiiv Sep 19 '18
Unless you need cross-platform support?
1
u/FierceDeity_ Sep 19 '18
I completely forgot about that mono doesn't have WPF... Which is a big fuckin shame
0
Sep 19 '18
[deleted]
1
u/FierceDeity_ Sep 19 '18
The Web ecosystem has completely transisted to cross platform since "v5", at least. ASP.NET Core is truly cross-platform. The desktop... well... GUI is a sad state, but the mono core runs fully well, which explains all the Unity cross platform games
-26
12
u/MrN_Nabhani Sep 18 '18
is there still any advantage for using Swing over JavaFx in terms of functionality, simplicity, or idk maybe memory?! Or is it something no one uses anymore?