java - JavaFX ScrollBar setOnMousePressed not working -


really liking javafx have come across problem , wondered if bug.

the scrollbar.setonmousepressed() doesn't seem fire when has been initialised handler. code below demonstrates problem:-

import javafx.application.application; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.control.scrollbar; import javafx.scene.layout.vbox; import javafx.stage.stage;  public class play extends application {     public static void main(string[] args) {         launch(args);     }      private static int cnt;      @override     public void start(stage primarystage) {         primarystage.settitle("bug?");         button btn = new button("this text replaced event handlers");          scrollbar scrollbar = new scrollbar();          // when pressing , releasing scrollbar thumb, decrements         // if replace scrollbar button, code below works might expect.         scrollbar.setonmousepressed( event -> btn.settext("x" + cnt++));         scrollbar.setonmousereleased( event -> btn.settext("x" + cnt--));          vbox root = new vbox();         root.getchildren().add(btn);         root.getchildren().add(scrollbar);          primarystage.setscene(new scene(root, 350, 250));         primarystage.show();     } } 

note, im running on jdk 1.8.0_66 64 bit on microsoft windows 10.

a simple workaround, suggested james_d, use eventfilters instead of setonmousepressed(), follows:-

so,

scrollbar.addeventfilter(mouseevent.mouse_pressed,             event -> btn.settext("x" + cnt++)); 

instead of

scrollbar.setonmousepressed( event -> btn.settext("x" + cnt++)); 

i believe .setonmousepressed() should work, doesn't because of bug in library. i've raised oracle , update answer once oracle clarifies.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -