This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

Posts tagged: JavaFX

JavaFX TableView with Database records

JavaFX has a nice looking TableView and it offers useful functionality, but the standard implementation is not useful for real-world database applications.

Why?

  • You must fill a TableView manually with records from the database, because JavaFX has no datasource support integrated. This means you have to use JDBC directly or libraries like EclipseLink or Hibernate, to fill your table.
  • If you fill your TableView manually, you miss support for database sort operations. JavaFX supports memory sort but if you have millions of records, it is not the best idea to fetch all records for simple sort operations.
  • Support for lazy-loading/load-on-demand is not integrated. With load-on-demand, I mean the possibility to load records when the UI requests them. If you have a database table with e.g. 10 million records, the UI should load the first 1.000 (or more). If the user needs more records, the TableView should load more automatically. I won't use paging for this use case.
  • Column resizing works well but is not user-friendly. The CONSTRAINED_RESIZE_POLICY is like auto-resize in JTable. It allows column resizing within the table width, but it is not possible to enlarge the table horizontally. The UNCONSTRAINED_RESIZE_POLICY allows enlarging but adds an extra "column". This column is not selectable and fills the gap if the total column width is smaller than the table width. We need a resize policy that supports both and such a policy is not included in JavaFX.
  • The default selection model offers ROW and CELL selection, but in ROW mode you don't see the selected cell (= focus). If you need an editable TableView it is a problem if you can't see the selected cell.
  • If you need an editable table, you have support but not a working solution - especially if you work with database records.
  • Missing support for Insert and Delete rows with keyboard. It is possible to start updating values with <F2>.
  • No standardized solution for Master/Detail with multiple levels.

I don't say that it is not possible to implement above features, but if you don't create a custom control, you'll have a lot of boilerplate code in your applications. Some features are not trivial because the APIs do not offer relevant methods and the JavaFX control development model hides a lot of functionality. Of course, it is always possible to create new controls, but it is not cool to reinvent the wheel. One problem is that the TableView implementation together with the TableViewSkin and TableViewBehavior are not very developer friendly, because the classes are not really extendable. Most important methods are private or final. Another problem is that you need css and code together, for specific features. It is easy to change padding with css but where is a method in the API?

A solution for the datasource problem is offered from the DataFX project.

I'm a developer for business application frameworks and most applications are connected to databases with or without an application server. The applications must be fast and responsive. It helps if an application looks fancy, but functionality is more important.

Sometimes I think that JavaFX controls are really impressive but their developers should create real-world (business) applications.
If you get feedback from your paying customers you know exactly what you have to do and which features are good and important. My personal opinion is that Oracle should ask application developers and work with them to solve real-world problems.

With JVx, we have a full-stack-application framework that solves our business problems and we try to implement new UI technologies as soon as they are market relevant. So we started with the integration of JavaFX. We tried to solve above points, because they are very important for us.

Our current development progress is available as OpenSource (sub)Project of JVx and is licensed under Apache 2.0.

What we have solved so far?

All above points, but more or less clean. Some solutions are "dirty" because we have no API or didn't find a better solution.

"Dirty" solutions?

  • Column resize policies are supported but relevant features are missing or hidden, e.g. The TableView retrieves the content-width from the TableViewSkin (via general control properties - getProperties()) because the TableView has no access to scrollbars and the content width is different with and without vertical scrollbar. This is dirty and does not work in any cases in the original TableView, but this information is important if you develop your own resize policy! We need more and better access through the API.
  • Load-on-demand works but this is the dirtiest hack. It is not so easy to add a feature that was not planned. We used a custom event dispatcher to made it possible. We must check the implementation with every TableView update...
  • Show focused cell in ROW selection mode is possible with CSS but it is horrible.

There are more funny solutions, but the result just works. One additional and maybe interesting feature is, that we don't change the row height if you start editing. It was annoying that the table height toggled in edit mode.

Our current solution offers an editable TableView which is connected to a database (2 or 3-tier architecture). All sort operations are delegated to the database. The solution supports any Master/Detail relations (memory, db and mixed) and loads records automatically from the database. All Insert/Update/Delete operations are sent to the database.

Our current solution is not finished because we don't have specific cell editors. We have to implement cell editors for Number/Date/Images/LOVs (= ComboBox).

A first impression:

TableView with Database

TableView with Database

  Country - States - Districts

with Master/Detail/Detail

The database:

CREATE TABLE COUNTRIES
(
  ID      INTEGER IDENTITY,
  COUNTRY VARCHAR(200) NOT NULL,
  EU      CHAR(1) DEFAULT 'N' NOT NULL,
  constraint CTRY_UK UNIQUE (COUNTRY)
)

CREATE TABLE STATES
(
  ID      INTEGER IDENTITY,
  CTRY_ID INTEGER NOT NULL,
  STATE   VARCHAR(200) NOT NULL,
  constraint STAT_UK UNIQUE (STATE),
  constraint STAT_CTRY_ID_FK FOREIGN KEY (CTRY_ID) REFERENCES COUNTRIES (ID)
)

CREATE TABLE DISTRICTS
(
  ID       INTEGER IDENTITY,
  STAT_ID  INTEGER NOT NULL,
  DISTRICT VARCHAR(200),
  constraint DIST_UK UNIQUE (DISTRICT),
  constraint DIST_STAT_ID_FK FOREIGN KEY (STAT_ID) REFERENCES STATES (ID)
)

Oracle Forms with JavaFx and Swing

I'm sure that some of you have already used custom swing controls in Forms applications to enrich them. But have you tried to use JavaFx together with your Forms application?

JavaFx has cool effects, animations, controls, css styling and much more.

If you enter 'oracle forms javafx' or similar, in your favourite search engine, you get no specific results. So I think it is time to integrate JavaFx to an Oracle Forms application, isnt't it?

- It is a world premiere -


First, a screenshot:

Oracle Forms and JavaFx

Oracle Forms and JavaFx

We used the source code from the official example, that integrates JavaFx in a Swing application.

The result of our integration is a screen that contains Swing and JavaFx controls. If you change a value in the table, the chart is updated immediately. It is really cool because the chart has nice transition effects.

You can combine rapid application development with modern controls and new development concepts.

JavaFx 2.0 and Business Applications

JavaFx 2.x has some nice UI components. It has new APIs and it is completely different to Swing. Of course, you can mix JavaFx components with Swing components, but the LaF is not the same! The new styling mechanism of JavaFx are really great.

But for me, its not a big step forward in the evolution. It is another UI library, of course a visually appealing. I miss an application framework or components with built-in support for modern applications. From my point of view, there is not enough focus on business applications. A business application is not a simple table or chart with some nice looking bars. A business app should handle millions of records, should allow keyboard navigation in all variants, should be fast, should save costs and time.

What should be different?

A standard JavaFx 2 application looks very nice because the standard style is modern. Also styling options are better than ever.

For me, the whole API is too much focused on Lists, POJOs, Generics and Object Bindings. Of course, it is cool for small apps, but you waste time with boilerplate code. If you have a database application with 5 simple tables that contains master data, and you need edit screens, you duplicate your source code 5 times because you have no support for dynamic usage. If you work without Generics, it is not really funny because JavaFx uses it everywhere.

Load-on-demand of records is possible if you do it manually, but it is not included in the controls. "Touch-scrolling" would be great. Compared to other UI libraries (swing, swt, qt), you can't change the default operation of UI controls because you don't have access to internal listeners, scrollbars, Behaviour, ... Some parts are customizable but these are more the exception.

The whole event handling is sometimes very complex, because you don't know what event type you have to use, where the type is declared and which event is the correct one. And inner classes are not the best solution for clarity. Because of Generics you have a lot of configuration work and you are not sure if everything works as expected. Without powerful IDEs you have no chance. Sometimes you have events but nothing happened....
That parts are not the real problem because it requires a certain amount of time to understand new classes. But must things always be complex rather than simple?

But it is great to write source code instead of crazy scripts.

What else?

The version number 2 is too high, because it is still not mature. JavaFx shows what is possible (scene graph, effects, web and video content) but it is not simple to use. But maybe it is perfect to combine only some parts with other mature toolkits like Swing or Swt?

It is not the library that bothers me, but it brings little relief for a developer. Why not just use Pivot? Yes... the web view is powerful ;-)

What should be done?

Focus on Business applications. Integrate an application framework that saves development time. Controls should not be so restrictive!

Fundtruhe - APIs

Zum Wochenausklang einige interessante Links für mobile Anwendungen:

  • JSON Serializer

    Ein noch recht junges Projekt für die Objektserialisierung mit JSON.

  • JFXtras

    Im Rahmen des Projektes werden Erweiterungen für Java FX entwickelt. Unter anderem neue Komponenten und Effekte.

  • AiCharts (Kommerziell)

    Eine mächtige Bibliothek für die Erstellung von Charts unter Android.