Jruby - Javafx : How to add icon to button?

20.3k views Asked by At

I'am struggling for loading an icon (png Format) for Javafx and Jruby with jrubyfx, I did not find any example or docs so I tried :

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>

So I'am confused about the correct syntax :(

Thanks for your help :)

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

1

There are 1 answers

0
reme On BEST ANSWER

you might also want to take a peak at https://docs.oracle.com/javafx/2/ui_controls/button.htm

Image -> ImageView -> button.setGraphic

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

OR

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