java - JavaFX fill a table view not possible -
this question has answer here:
i started javafx , wanted create tableview
3 columns can display values. created tableview
, columns scene editor fxml file. created class named values
special properties matched columns should fit in. set observable list "value" objects in items of table. when start application, shows me empty table. looked 4 hours in internet , still not found answer why not working me.
here code:
value class:
public class values { public simpledoubleproperty psi = new simpledoubleproperty(0); public simpledoubleproperty alpha = new simpledoubleproperty(0); public simpledoubleproperty delta = new simpledoubleproperty(0); public values(double _psi, double _alpha, double _delta) { setpsi(_psi); setalpha(_alpha); setdelta(_delta); } private void setpsi(double p){ psi.set(p); } private void setalpha(double p){ alpha.set(p); } private void setdelta(double p){ delta.set(p); } }
controller:
@fxml label psi; @fxml label alpha; @fxml label delta; @fxml textfield betafield; @fxml textfield lambdafield; @fxml textfield lambdasatfield; @fxml tableview<values> table; @fxml observablelist<values> oblist; @fxml tablecolumn <values,double> psicolumn; @fxml tablecolumn <values,double> alphacolumn; @fxml tablecolumn <values,double> deltacolumn; @override public void initialize(url location, resourcebundle resources) { psicolumn.setcellvaluefactory(new propertyvaluefactory<values, double>("psi")); alphacolumn.setcellvaluefactory(new propertyvaluefactory<values, double>("alpha")); deltacolumn.setcellvaluefactory(new propertyvaluefactory<values, double>("delta")); } @fxml protected void buttonpressed(){ try { calculation cal = new calculation(double.parsedouble(betafield.gettext()), double.parsedouble(lambdafield.gettext()), double.parsedouble(lambdasatfield.gettext())); alpha.settext("alpha: " + " " + cal.calculatealpha()); delta.settext("delta:"+ " " + cal.calculatedelta()); psi.settext("psi:"+ " " + cal.calculatepsi()); table.setitems(fxcollections.observablearraylist(cal.calculateevaluaiontable())); }catch (nullpointerexception e){ e.printstacktrace(); } }
and fxml:
<tab text="tab" fx:id="tabe"> <content> <anchorpane minheight="0.0" minwidth="0.0" prefheight="180.0" prefwidth="200.0"> <children> <tableview layoutx="4.0" layouty="4.0" prefheight="192.0" prefwidth="370.0" fx:id="table"> <columns> <tablecolumn prefwidth="120.0" text="psi" fx:id="psicolumn" /> <tablecolumn prefwidth="120.0" text="alpha" fx:id="alphacolumn" /> <tablecolumn prefwidth="120.0" text="delta" fx:id="deltacolumn" /> </columns> </tableview> </children> </anchorpane> </content> </tab>
thanks help!
let <name>
denote constructor parameter of propertyvaluefactory
, let <name>
denote same string
, uppercase first letter.
propertyvaluefactory
can value 1 of following sources:
- the property getter, i.e. method
someobservablevalue <name>property()
. - the getter method, i.e. method
sometype get<name>()
.
none of exist in values
class.
for psicolumn
work, values
needs doubleproperty psiproperty()
method or double getpsi()
method. (same issue other columns)
Comments
Post a Comment