Jruby - Javafx:如何向按钮添加图标?

Jruby - Javafx : How to add icon to button?

我正在为使用 jrubyfx 加载 Javafx 和 Jruby 的图标(png 格式)而苦苦挣扎,我没有找到任何示例或文档,所以我尝试了:

1)

button_login = find('#button_login') # See ComplexControl.fxml
button_login.text = "#{t.login.form.button_login}"
button_login.graphic image("src/code/media/logo.png")

I get: failed to coerce javafx.scene.image.Image to javafx.scene.Node>

2)

button_login = find('#button_login') # See ComplexControl.fxml
button_login.text = "#{t.login.form.button_login}"
button_login.graphic = "src/code/media/logo.png"

I get: TypeError: cannot convert instance of class org.jruby.RubyString to class javafx.scene.Node>

所以我对正确的语法感到困惑:(

感谢您的帮助:)

jruby 9.1.15.0 (2.3.3) 2017-12-07 929fde8 Java HotSpot(TM) 64-Bit Server VM 25.161-b12 on 1.8.0_161-b12 +jit [linux-x86_64] - Ubuntu Xenial

您可能还想在 https://docs.oracle.com/javafx/2/ui_controls/button.htm

登顶

图像 -> ImageView -> button.setGraphic

img = image("src/code/media/logo.png") 
button_login.setGraphic ImageView.new(img) 

button_login.setGraphic ImageView.new(image("src/code/media/logo.png"))