1

Given a certain Java object, I would like to generate at runtime a visual interface for configuring certain properties of it. The Object properties to configure in this generated interface can be specified with annotations. They can be primitive types (or their wrappers) + Strings and arrays or collections of these types. The type of visual component to configure certain property depends on the type of such property (for example, a boolean may be configured with a list view with only two alternatives).

Does a library for doing this already exist in Java ? I am using JavaFX in my application, and I do not have any hope this already exists in this framework (but I would be happy of being wrong). However, if a Swing library doing this exists, I may be able to embed it in my JavaFX interface.

Sergio
  • 8,532
  • 11
  • 52
  • 94

1 Answers1

2

SceneBuilder definitely has a visual object property editor built into it, but unfortunately is not an open source project and I don't know of any pure JavaFX open source projects which are as feature-filled. So if you want a pure JavaFX solution, be prepared to do some coding yourself.

A basic approach to doing this is to use a TableView, introspect on the types of object members (or annotations or JavaFX builders if you prefer), and as a basis of that introspection, use cell factories for generating cell nodes to handle the display and editing of the cells displayed in the TableView.

Here is some sample code for a JavaFX property editor for a couple of basic types (string and boolean) taken from an answer to Multiple Components in one column of JavaFX TableView.

JavaFX contains a library of some basic cell factories which could act as building blocks for constructing your solution.

DataFX contains some code for generating your UI control cell factories from various data sources such as Java Beans, JDBC, XML, CSV, etc.

You may want to take a look at the FXForm2 project which does "Automatic form generation and binding to bean properties"

As you mention, if a Swing library doing this exists (and I'm sure it does, though I'm not familiar enough with Swing libraries to know what it is), you should be able to embed it into a JavaFX interface (if you use Java 8's SwingNode).

Community
  • 1
  • 1
jewelsea
  • 150,031
  • 14
  • 366
  • 406