Skip to content
Patrick Plenefisch edited this page Jul 24, 2013 · 3 revisions

JavaFX extensions

This page lists all the JRubyFX-specific extensions for JavaFX. Almost all JavaFX code should work identically in Ruby, but there are provided for convenience and to make JavaFX look more rubyish. This does not go over JRuby extensions, like jobj.var = foo mapping to jobj.setVar(foo). See the JRuby wiki for those. Basic knowledge of Ruby is assumed

General

The Number class provides sec, ms, min, hr, and hrs methods that return JavaFX Durations. They are most likely to be used in animations:

timeline do
  animate foo_property, 0.sec => 5.sec, from => to
end

ObservableValues, ObservableLists, and ObservableMaps all add a new method add_change_listener that registers the provided block via addListener(*ChangeListener) without warnings. ObservableValue's also provide a short version when only one block argument is given (arity 1) and gives the new value only:

foo_property.add_change_listener {|new| puts "Foo just changed to #{new}" }

All classes are augmented with property_accessor, property_reader, and property_writer. These methods function similarly to attr_* functions, except property_* methods get and set the observable value. Note these do not initialize the property. You must do that yourself before you use them.

class FooClass
  include JRubyFX
  property_accessor :bar

  def initialize
    @bar = SimpleDoubleProperty.new(this, "bar", 5)
  end
end

foo = FooClass.new
foo.bar #=> 5
foo.bar = 6
foo.bar_property.value #=> 6
foo.bar #=> 6

TODO: resource_root

UI via FXML

TODO:

  • fxml_root
  • fxml (class)
  • Stage#fxml, Stage#fxml=
  • load_fxml (instance)

UI via code

TODO

Clone this wiki locally