scrollpane - How to fire event when scrolling up,javafx -


i developing chat application on java , want use function used facebook retrieve chat history when user scroll up. tried "on scroll" action fire event whenever scroll reach top or down of scroll bar. want fire action event when scroll bar reach top in facbook chat box.

here example of want. hope you.

import javafx.application.application; import javafx.beans.value.changelistener; import javafx.beans.value.observablevalue; import javafx.event.actionevent; import javafx.event.eventhandler; import javafx.geometry.pos; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.control.label; import javafx.scene.control.scrollpane; import javafx.scene.layout.vbox; import javafx.stage.stage;  public class scrollutil extends application  {     private boolean scrolltobottom = false;     private boolean scrolltotop = false;      public static void main(string[] args)      {         launch(args);     }      @override     public void start(final stage stage) throws exception      {          final vbox root = new vbox();         final scrollpane scrollpane = new scrollpane();          final vbox vbox = new vbox();         vbox.setalignment(pos.bottom_center);          scrollpane.setcontent(vbox);          scrollpane.sethbarpolicy(scrollpane.scrollbarpolicy.never);          button button = new button("add");         button button3 = new button("scroll up");          button3.setonaction(new eventhandler<actionevent>()          {             @override             public void handle(actionevent actionevent)              {                 scrolltotop = true;                  scrollpane.setvvalue(scrollpane.getvmin());                 system.out.println("vmin= "+scrollpane.getvmin() + "; vmax = " + scrollpane.getvmax() + "; vvalue" + scrollpane.getvvalue());             }         });          button.setonaction(new eventhandler<actionevent>()          {             @override             public void handle(actionevent actionevent)              {                 vbox.getchildren().add(new label("hallo"));                 scrolltobottom = true;                 //system.out.println(scrollpane.getvmin() + "; max = " + scrollpane.getvmax() + "; " + scrollpane.getvvalue());             }         });          scrollpane.setvvalue(scrollpane.getvmax());         scrollpane.vvalueproperty().addlistener(new changelistener<number>()          {           @override           public void changed(observablevalue<? extends number> observable, number oldvalue, number newvalue)            {             if(scrolltobottom)             {               scrollpane.setvvalue(scrollpane.getvmax());               scrolltobottom = false;             }              if(newvalue.doublevalue() ==0)             {                 vbox.getchildren().add(new label("hallo"));                 system.out.println("min value ="+scrollpane.getvmin());                 //scrollpane.setvvalue(scrollpane.getvmin());                 scrolltotop = true;                 system.out.println("now chat history");             }           }         });          button button2 = new button("scroll");         button2.setonaction(new eventhandler<actionevent>()          {             @override             public void handle(actionevent actionevent)              {                 scrollpane.setvvalue(double.max_value);             }         });          root.getchildren().addall(scrollpane, button, button2, button3);         scene scene = new scene(root);         stage.setscene(scene);         stage.show();     } } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -