java - JavaFX, How do I trigger an event if someone check a CheckBox in Tableview -


i hava big problem in javafx. created tableview added checkboxes tableview. want trigger event if check checkbox in tableview. tried different ways have same problem. start program , "checkbox trigger event" runs 5 times before showing gui. after can click on checkboxes nothing happened. code , hope u can me. thx!

controller.class

package gui;  import java.io.ioexception; import java.util.arraylist;  import javafx.beans.value.observablevalue; import externalressources.trafficvolume; import javafx.collections.fxcollections; import javafx.collections.observablelist; import javafx.event.actionevent; import javafx.fxml.fxml; import javafx.scene.control.button; import javafx.scene.control.checkbox; import javafx.scene.control.menubar; import javafx.scene.control.menuitem; import javafx.scene.control.tablecolumn; import javafx.scene.control.tableview; import javafx.scene.control.cell.checkboxtablecell; import javafx.scene.control.cell.propertyvaluefactory; import javafx.scene.layout.anchorpane; import javafx.scene.layout.gridpane; import javafx.stage.stage; import javafx.util.callback;  public class tvidselectionpanelcontroller {       @fxml     private button backbutton;     @fxml     private button test;     @fxml     private menuitem menuitemsettings;     @fxml     private menubar menubar;     @fxml     private gridpane gridpanetvid;     @fxml     private tableview<trafficvolume> tabletvid;     @fxml     private tablecolumn<trafficvolume, string> tablecoltvid;     @fxml     private tablecolumn<trafficvolume, string> tablecolflightlvl;     @fxml     private tablecolumn<trafficvolume, checkbox> tablecolcheckbox;     @fxml     private anchorpane tablepane;      private exchangecontroller exchange;     public observablelist<trafficvolume> list = fxcollections.observablearraylist();      @fxml     private void handlebackbutton(actionevent event) throws ioexception     {                }      public void init(exchangecontroller ex)     {         this.exchange =ex;     }      @fxml        public void initalize() throws ioexception     {         this.choosedata();     }      @fxml     private void choosedata()     {         switch(exchange.getselectedebg())         {             case "central":             {                 this.createtable(exchange.getcentraltvid());             }             case "west":             {                 this.createtable(exchange.getwesttvid());             }             case "east":             {                 this.createtable(exchange.geteasttvid());             }             case "north":             {                 this.createtable(exchange.getnorthtvid());             }             case "south":             {                 this.createtable(exchange.getsouthtvid());             }         }     }       private void createtable(arraylist<arraylist<string>> listtvid)     {         for(int i=0;i<listtvid.size();i++)         {             list.add(new trafficvolume(listtvid.get(i).get(0),listtvid.get(i).get(1)));         }         tablecolumn<trafficvolume, string> tvids = new tablecolumn<trafficvolume, string>("tv-id");         tablecolumn<trafficvolume, string> flvl = new tablecolumn<trafficvolume, string>("flight level");            tablecolumn<trafficvolume, boolean> checkedcol = new tablecolumn<trafficvolume, boolean>("active");         tabletvid.setitems(list);         tabletvid.getcolumns().addall(tvids,flvl,checkedcol);         tvids.setcellvaluefactory(new propertyvaluefactory<trafficvolume, string>("name"));         flvl.setcellvaluefactory(new propertyvaluefactory<trafficvolume, string>("flightlvl"));         checkedcol.setcellvaluefactory(new propertyvaluefactory<trafficvolume, boolean>("check"));         checkedcol.setcellfactory(checkboxtablecell.fortablecolumn(checkedcol));         checkedcol.seteditable(true);         tabletvid.seteditable(true);          checkedcol.setcellfactory(checkboxtablecell.fortablecolumn(new callback<integer, observablevalue<boolean>>()         {             @override             public observablevalue<boolean> call(integer param)             {                  return list.get(param).checkedproperty();             }         }));           (trafficvolume trafficvolume : list) {             trafficvolume.checkedproperty().addlistener((obs, waschecked,isnowchecked) -> {                   system.out.println("checked property " + trafficvolume.getname() +                             " changed "+waschecked + " " + isnowchecked);             });         }      }         //switch scene     @fxml     private void handlesettings(actionevent event) throws ioexception     {                exchange.settvidselectionpanelscene(menubar.getparent().getscene());         exchange.settvidselectionpanelstage((stage) menubar.getparent().getscene().getwindow());         exchange.setlastscene(exchange.gettvidselectionpanelscene());         exchange.setlaststage(exchange.gettvidselectionpanelstage());         exchange.initalizestageoptions(event, menubar);        }   } 

trafficvolume.class

    package externalressources;  import javafx.beans.property.booleanproperty; import javafx.beans.property.simplebooleanproperty; import javafx.beans.property.simplestringproperty; import javafx.beans.value.observablebooleanvalue;  public class trafficvolume {     private  simplestringproperty name;     private  simplestringproperty flightlvl;     private  booleanproperty check;      public trafficvolume(string name, string flightlvl)      {         this.name = new simplestringproperty(name);         this.flightlvl = new simplestringproperty(flightlvl);         this.check = new simplebooleanproperty(false);     }      public string getname() {         return name.get();     }      public string getflightlvl() {         return flightlvl.get();     }      public boolean getcheck() {         return check.get();     }      public booleanproperty checkedproperty()     {         system.out.println("test");         return check;     }      public void setcheck(boolean checked)     {         this.check.set(checked);     }      public observablebooleanvalue ischecked()     {         system.out.println("test");         return check;     }  } 

console output

checked property educntr changed false true checked property educntr changed false true checked property educntr changed false true checked property educntr changed false true checked property educntr changed false true checked property eduffm1f changed false true checked property eduffm1f changed false true checked property eduffm1f changed false true checked property eduffm1f changed false true checked property eduffm1f changed false true checked property eduffm14 changed false true checked property eduffm14 changed false true checked property eduffm14 changed false true checked property eduffm14 changed false true checked property eduffm14 changed false true checked property eduffm24 changed false true checked property eduffm24 changed false true checked property eduffm24 changed false true checked property eduffm24 changed false true checked property eduffm24 changed false true checked property eduffm34 changed false true checked property eduffm34 changed false true checked property eduffm34 changed false true checked property eduffm34 changed false true checked property eduffm34 changed false true 

add listeners item's checkedproperty()s:

@fxml    public void initalize() throws ioexception     {      tablecolumn<trafficvolume, string> tvids = new tablecolumn<trafficvolume, string>("tv-id");     tablecolumn<trafficvolume, string> flvl = new tablecolumn<trafficvolume, string>("flight level");        tablecolumn<trafficvolume, boolean> checkedcol = new tablecolumn<trafficvolume, boolean>("active");     tabletvid.setitems(list);      (trafficvolume trafficvolume : list) {         trafficvolume.checkedproperty().addlistener((obs, waschecked, isnowchecked) -> {             system.out.println("checked property " + trafficvolume.getname() +                 " changed "+waschecked + " " + isnowchecked);         }     }      // ... } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -