5

Is there a Java alternative to these technologies? I find the data binding capabilities and INotifyPropertyChanged of most use (along with containers and elements of the sort), but the lack of cross-platform of .NET makes me think of Java. What do you suggest? Is there any equivalent product? One that implements XAML?

Alvaro
  • 11,797
  • 9
  • 40
  • 57
  • One can argue that WPF started out as a shameless rip-off of J2EE. Just as .Net itself was a shameless rip-off of Java (just using "static void Main()" and "string", instead of "static void main()" and "String"). IMHO... – paulsm4 Nov 18 '12 at 21:28
  • 7
    It could be argued but wouldn't answer the question being asked would it? – Benjamin Gale Nov 18 '12 at 21:37
  • 2
    WPF as a copy of J2EE? What are you smoking? – Paolo Nov 18 '12 at 21:47
  • Take a look at http://stackoverflow.com/q/2016470/116249 as well – Patrick Nov 18 '12 at 23:01

2 Answers2

7

The technology (WPF)

If you are looking for an alternative to WPF for the Java platform you should take a look at JavaFX.

The technology is very similar to WPF in the following ways:

  • The applications user interface is made up of a tree of objects called a scene graph consisting of Node objects (which is similar to the WPF visual tree which consists of UIElement objects).
  • The Pane node and it's derivatives are conceptually similar to the WPF layout panels.
  • The user interface can be created using a markup called FXML which is similar to XAML.
  • JavaFX provides objects that represent properties which support binding and change notification (think dependency properties). Unlike dependency properties they are not tied to the user interface technology so can be used by your model classes.
  • The user interface can be styled using CSS.

Take a look at my answer to the question how does JavaFx compare to WPF which provides a much more detailed (but still high level) comparison of WPF and JavaFX.

The design pattern (MVVM)

The MVVM pattern is a specialisation of the presentation model pattern. It is possible to create a variation of this in JavaFX as the platform provides properties that support binding and the presentation model is basically an object that encapsulates the state of the model and provides operations that act upon that state.

Most examples I have seen though use a variant of the model-view-presenter pattern. Out of the box JavaFX supports a very simple MVP structure where each view is associated with a 'controller' class. This is fine for small applications but doesn't really provide great separation of concerns.

Community
  • 1
  • 1
Benjamin Gale
  • 12,977
  • 6
  • 62
  • 100
2

Maybe you should keep an eye on the fantastic MVVMFX Framework. Based on the parallels between WPF and JavaFX like descriptive UI declaration (FXML/XAML) they tried to adopt best practices of the development with WPF.

It supports, of course, Databinding concepts and implements the necessary interfaces for notifications between the view, viewModel and the model. UI and its UI-Logic (code behind) is realized with fxml-files (created with Scene Builder) and the obligatory Java class. With many good examples it isn't that hard to understand their concepts because it is a strict implementation of the purest MVVM-Pattern. All you need is to establish the framework in your project dependencies.