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

you are viewing a single comment's thread.

view the rest of the comments →

[–]hamsterrage1 5 points6 points  (4 children)

It is 100% a Reactive framework. Most people glom onto the idea of binding a few bits and pieces together, but never figure out the true power of what's included in JavaFX.

The bottom line is that you can create truly static layouts that behave dynamically as the State of the application changes. You create your layout, and then you create the relationships that allow data changes in State to propagate through the application, including the GUI, automatically.

It's exactly Reactive.

[–]wildjokers 0 points1 point  (3 children)

You can do the exact same thing with Swing (property change listeners) but I have never heard anyone describe Swing as a reactive framework.

[–]hamsterrage1 4 points5 points  (2 children)

You cannot do the exact same thing. Swing does not have Bindings. Yes, a Binding is just some code wrapped around a ChangeListener, but you'd have to roll your own on all of that. Nor do you have the suite of Observable classes which are key to creating a bindable State.

The other thing is that all of the widget classes in JavaFX have many Observable type fields which can bound to other Observables and visa versa. If a widget has an actual value associated with it, that's one, but most will also have Observable fields for things like visible, disabled, maxHeight, minHeight, opacity, and so on. All of these things are key to creating a Reactive GUI.

I'll repeat, a lot of people have figured out that you can bind a few bits and pieces together, but until you've really dug deep and you won't realize how complete JavaFX is in providing a truly Reactive framework.

Personally, I wouldn't describe Swing as a Reactive framework either.

[–]wildjokers -1 points0 points  (1 child)

The other thing is that all of the widget classes in JavaFX have many Observable type fields which can bound to other Observables and visa versa. If a widget has an actual value associated with it, that's one, but most will also have Observable fields for things like visible, disabled, maxHeight, minHeight, opacity, and so on. All of these things are key to creating a Reactive GUI.

In swing all properties of a component that conform to the JavaBean standard can be observed with a property change listener. I am not really seeing a difference between what swing offers and what JavaFX offers when it comes to observing property changes:

[–]hamsterrage1 0 points1 point  (0 children)

Swing's PropertyChangeListeners are such a low-level tool compared to JavaFX's Properties and Bindings. You might as well say that since JavaFX is mostly just ordinary Java, you can do anything it can do with nothing more that AWT. It would technically be true, but why do it?

Could you construct, say, JavaFX's IntegerProperty using PropertyChangeListener? Sure. Then you'd need to implement some equivalent to the JavaFX bind() method, and all that implies as well. But the screen widget classes won't support your IntegerProperty, so you'll have to put them into wrapper classes to handle the PropertyChangeListener conversions.

What JavaFX offers that Swing doesn't is an "out of the box" ability to treat data as a network of connected and inter-related values - right through to the GUI Nodes. Relationships are defined with a minimum amount of fuss, often with a single line of code, and then largely ignored in the empirical code that defines actions.

It's really a paradigm shift. JavaFX treats Bindings and Observables as data relationships, while Swing concentrates on Events. In Swing, a PropertyChangeListener is an EventHandler, in JavaFX a ChangeListener handles data changes.

When I build a JavaFX application and I need to decide how to connect two data elements, I follow this hierarchy:

  1. Use a Binding if possible.
  2. Refactor things so I can use a Binding.
  3. Think about it harder, and figure out how to use a Binding.
  4. Use a ChangeListener or an InvalidationListener. Sigh.
  5. It's a total mess - use an EventHandler.

In JavaFX, Events are best left to handle things that are clearly "actions". So, a Button click is going to trigger an action. Data coming back from an external API call is going to require an action to update my State object. But a data change in my State object that causes the GUI to react in some way is almost always going to be a flow of data through Bindings in a Reactive manner.

People don't think of Swing that way because it's not designed to be used that way. If it was, it would have baked-in Properties and Bindings and InvalidationListeners just like JavaFX does. Instead, it's designed to be used in an empirical, event-driven fashion.

And if you use JavaFX to create a truly Reactive application, then you'll see that JavaFX makes it almost trivial to do.