javafx 2 - How to send events from one Node to another Node -


i have pane listens wheel mouse scroll; have scroll bar automatically listens wheel mouse scroll. know how send scroll event captured pane scrollbar.

i can’t use scroll pane because need custom implementation of pane, tried use scroll pane , did not cover needs.

i tried fire event , other method can event passed/propagated/sent scrollbar.

thanks in advance

sample application:

package com.test;  import javafx.application.application; import javafx.beans.value.changelistener; import javafx.beans.value.observablevalue; import javafx.event.event; import javafx.event.eventhandler; import javafx.geometry.orientation; import javafx.scene.scene; import javafx.scene.control.scrollbar; import javafx.scene.input.scrollevent; import javafx.scene.layout.borderpane; import javafx.scene.layout.pane; import javafx.stage.stage;  public class scrolltest extends application{     @override    public void start(stage primarystage) throws exception {        final borderpane root = new borderpane();       final pane pane = new pane();      root.setcenter(pane);       final scrollbar scrollbar = new scrollbar();      root.setright(scrollbar);        pane.addeventfilter(scrollevent.any, new eventhandler<scrollevent>(){         @override         public void handle(scrollevent arg0) {            system.out.println("scrolling on pane");             event.fireevent(scrollbar, arg0); //           scrollbar.geteventdispatcher().dispatchevent(arg0, arg1)         }      });         scrollbar.setorientation(orientation.vertical);      scrollbar.valueproperty().addlistener(new changelistener<number>() {         @override         public void changed(observablevalue<? extends number> ov, number old_val, final number new_val) {            system.out.println("scrollbar.valueproperty() changed");         }      });        primarystage.setscene(new scene(root, 600, 600));      primarystage.show();    }     public static void main(string[] args) {       launch(args);    }  } 

seems, question equal need of custom scroll pane implementation.

i think, possible way - parse event, , make scroll bar change value, when event comes (add listener on event on pane, parse whether scroll or down, , use method increment or decrement of scroll bar).

also, use implementation scroll event sending. use scratch implementation :

/**  * send scrollevent in center of control  *  * @param wrap wrap, receive event  * @param scrollx number of pixels scroll x coordinate  * @param scrolly number of pixels scroll y coordinate  */ protected static void sendscrollevent(final scene scene, node node, double scrollx, double scrolly) {     double x = node.getlayoutbounds().getwidth() / 4;     double y = node.getlayoutbounds().getheight() / 4;     sendscrollevent(scene, node, scrollx, scrolly, scrollevent.horizontaltextscrollunits.none, scrollx, scrollevent.verticaltextscrollunits.none, scrolly, x, y, node.getlayoutbounds().getminx() + x, node.getlayoutbounds().getminy() + y); }  protected static void sendscrollevent(final scene scene, final node node,         double _scrollx, double _scrolly,         scrollevent.horizontaltextscrollunits _scrolltextxunits, double _scrolltextx,         scrollevent.verticaltextscrollunits _scrolltextyunits, double _scrolltexty,         double _x, double _y,         double _screenx, double _screeny) {     //for 2.1.0 :     //final scrollevent scrollevent = scrollevent.impl_scrollevent(_scrollx, _scrolly, _scrolltextxunits, _scrolltextx, _scrolltextyunits, _scrolltexty, _x, _y, _screenx, _screeny, false, false, false, false);     //for 2.2.0 :     //interpretation: eventtype<scrollevent> eventtype, double _scrollx, double _scrolly, double _totalscrollx, double _totalscrolly, horizontaltextscrollunits _scrolltextxunits, double _scrolltextx, verticaltextscrollunits _scrolltextyunits, double _scrolltexty, int _touchpoints, double _x, double _y, double _screenx, double _screeny, boolean _shiftdown, boolean _controldown, boolean _altdown, boolean _metadown, boolean _direct, boolean _inertia)     //for 8.0 before b64 , rt-9383     //final scrollevent scrollevent = new scrollevent.impl_scrollevent(scrollevent.scroll, _scrollx, _scrolly, _scrollx, _scrolly, _scrolltextxunits, _scrolltextx, _scrolltextyunits, _scrolltexty, 0, _x, _y, _screenx, _screeny, false, false, false, false, false, false);      //new scrollevent(eventtype<scrollevent> eventtype,      //double x, double y, double screenx, double screeny,      //boolean shiftdown, boolean controldown, boolean altdown, boolean metadown,      //boolean direct, boolean inertia, double deltax, double deltay, double gesturedeltax, double gesturedeltay,      //scrollevent.horizontaltextscrollunits textdeltaxunits, double textdeltax,      //scrollevent.verticaltextscrollunits textdeltayunits, double textdeltay, int touchcount)     final scrollevent scrollevent = new scrollevent(scrollevent.scroll,             _x, _y, _screenx, _screeny,             false, false, false, false,             false, false, _scrollx, _scrolly, 0, 0,             _scrolltextxunits, _scrolltextx,             _scrolltextyunits, _scrolltexty, 0, null /* pickresult?*/);      point2d pointonscene = node.localtoscene(node.getlayoutbounds().getwidth() / 4, node.getlayoutbounds().getheight() / 4);     final pickresultchooser result = new pickresultchooser();     scene.getroot().impl_picknode(new pickray(pointonscene.getx(), pointonscene.gety()), result);     node nodetosendevent = result.getintersectednode();     nodetosendevent.fireevent(scrollevent); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -