Saturday, July 16, 2016

Windows Hack for JavaFX UNDECORATED Stages

Stages initialized with StageStyle.UNDECORATED display a shadow on the Mac and Linux, making the custom window standout from the apps running in the background.  On Windows, UNDECORATED does not display a shadow, so if the window is a light color, it may bleed into the background if there is no border.

This hack wraps up the Parent from an FXML file into a VBox.  A DropShadow is added to the Parent ("your content") and the VBox is padded to allow for the DropShadow display.  Then both the Scene and the VBox are set to be completely transparent.

The StageStyle for this Windows hack must be TRANSPARENT.

Wednesday, July 13, 2016

Calling a Swing Listener from JavaFX

This blog post demonstrates how to call a legacy Swing ActionListener from JavaFX.  A JButton ActionListener increments a variable and sets a JTextField to the incremented value.  A JavaFX Button is added to the form that calls the same ActionListener object used by the Swing code.


The Swing / JavaFX Hybrid App

Adding JavaFX to a Swing app incrementally is a great way for an organization to learn about the productivity benefits, API, and deployment characteristics of JavaFX.  If your app needs a new form for the next release, build it in JavaFX (with Scene Builder and CSS) and integrate it in the existing Swing code.  That way, the new feature can give early feedback on how well JavaFX is working without breaking existing functionality.


Monday, July 11, 2016

Binding a JavaFX ChoiceBox to a Label

If you're coming from a Swing background, you're used to adding listeners to controls and using programming logic to map the values into controls.  JavaFX Binding offers a clean declarative syntax that avoids the often trivial packing and unpacking of data structures.

This example drives the contents of a Label off of a ChoiceBox. The Bindings.selectString() line associates the selected ChoiceBox item -- a model object -- with the Label.  Since the Label only displays a text value, there is an additional conversion to dig out the "description" property.

TV ListView App Video Series

This 6-part JavaFX video series demonstrates how to create a custom ListCell for use in a ListView. You'll walk through an example that

  1. Builds a UI in Scene Builder,
  2. Styles the UI using CSS, and
  3. Extends the class ListCell for special rendering and behavior.
The app is a TV program browser where the ListView's items are large.  Selecting items produces a strong visual cue through a bold border and through the addition of more information.

Screenshot of TV ListView App
Follow this link to view the video series.