What is JRubyFX?

Sep 5, 2015

JRubyFX?

For anyone not familiar with JRubyFX, check it out. The tl;dr is that JRubyFX allows you to harness the power of 3 things:

  1. Java
  2. Ruby
  3. JavaFX

Really, JRubyFX is the glue that binds JRuby with JavaFX. And I love it. Love it.

Now what is JavaFX? JavaFX is the GUI toolkit that is meant to entirely replace the old, hideous Java thick client applications. While it doesn’t look entirely native, it really does go a long way (compared to swing). Because we are writing ruby, the code is just so expressive and easy to understand (actual Brakeman Pro code):

So what’s going on here?

  1. text() creates a text element, one of the most basic controls. Guess what it does?
  2. Inside of the block passed to text(), we add a style_class. JavaFX has a CSS-like language to style things as you would a website. The code inside the block is implicitly called on the newly created object.
  3. JavaFX has a nice binding API so as elements resize the page, you have great control over how other controls react. In this case, we wrap the text based on the width of the drawer which is just an element that will essentially wrap everything in the end.
  4. Now we take our text objects and throw them into a vbox. A vbox is just a control that will position it’s children elements in a vertical sequential list.

So that’s the high level overview, hopefully this will serve as a good post for future JRubyFX related posts.