Friday 15 May 2015

javafx - how to make a table visible with custom rows & column -



javafx - how to make a table visible with custom rows & column -

i have next code create custom table. in output shows many rows doesn't contain values. display 2 rows , 1 columns. there solution this, else javafx produces default. there alternate way create table. may using gridpanebuilder

private tableview<person> table = new tableview<person>(); private final observablelist<person> info = fxcollections.observablearraylist( new person("jacob"), new person("isabella") ); public static void main(string[] args) { launch(args); } @override public void start(stage stage) { scene scene = new scene(new group()); stage.settitle("table view sample"); stage.setwidth(450); stage.setheight(500); final label label = new label("address book"); label.setfont(new font("arial", 20)); table.seteditable(true); tablecolumn firstnamecol = new tablecolumn("first name"); firstnamecol.setminwidth(100); firstnamecol.setcellvaluefactory( new propertyvaluefactory<person, string>("firstname")); table.setitems(data); table.getcolumns().addall(firstnamecol); final vbox vbox = new vbox(); vbox.setspacing(5); vbox.setpadding(new insets(10, 0, 0, 10)); vbox.getchildren().addall(label, table); ((group) scene.getroot()).getchildren().addall(vbox); stage.setscene(scene); stage.show(); } public static class person { private final simplestringproperty firstname; private person(string fname) { this.firstname = new simplestringproperty(fname); } public string getfirstname() { homecoming firstname.get(); } public void setfirstname(string fname) { firstname.set(fname); } }

you can set columns take much space possible by:

mytable.setcolumnresizepolicy(tableview.constrained_resize_policy);

i don't know if there easy way set height of table according amount of rows, set maxheight of table accoring amount of rows multiplied rowheight:

mytable.setmaxheight(countofrows * rowheight + headerheight);

and more flexible way utilize javafx binding, when add together or delete row height of table changes.

javafx javafx-2 javafx-8

No comments:

Post a Comment