FxBuilder 0.1-ALPHA - No Fluff Just Stuff

FxBuilder 0.1-ALPHA

Posted by: Andres Almiray on December 6, 2008

Psst... can you keep a secret? Groovy's SwingBuilder and JavaFX components can be used together :-D
Which prints when executed

SwingButton [boundsInLocal=Rectangle2D [minX = 0.0, minY=0.0, maxX=34.0, maxY=10.0, width=34.0, height=10.0], boundsInParent=Rectangle2D [minX = 0.0, minY=0.0, maxX=34.0, maxY=10.0, width=34.0, height=10.0]
JComponentWrapper [boundsInLocal=Rectangle2D [minX = 0.0, minY=0.0, maxX=34.0, maxY=10.0, width=34.0, height=10.0], boundsInParent=Rectangle2D [minX = 0.0, minY=0.0, maxX=34.0, maxY=10.0, width=34.0, height=10.0]

The first element is a javafx.ext.swing.SwingButton, JavaFX's native button based on Swing. The second one is a regular JButton wrapped by SwingComponent.wrap(), which is the solution to embedding any Swing component into a JavaFX scene. You may have noticed that the first button has an action property whose value is a Groovy closure but JavaFX knows nothing about them, however, it understands Function and in order to make things work a converter is being used under the covers. Now about the second component, the regular way to register event listeners on a JButton in SwingBuilder is used (because of the actionPerformed property) without being hindered by the fact that the component is actually another JavaFX class, again the builder knows how to route and convert attribute values as needed. Firing a click event in a programmatic way is a bit cumbersome as you can see, but it demonstrates that the button work as expected.

The builder is not yet capable of combining all the required elements to build a Stage/Scene combo, in other words a simple JavaFX application, hence the version number 0.1-ALPHA. It can be downloaded directly from the trunk at this location. Feedback is always appreaciated.

Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »