Javafx. Scene. Control. tableview constrained_resize_policy

Source: Internet
Author: User
Tags addall
Package tableview; import javafx. application. application; import javafx. beans. property. simplestringproperty; import javafx. beans. property. stringproperty; import javafx. collections. fxcollections; import javafx. collections. observablelist; import javafx. scene. group; import javafx. scene. scene; import javafx. scene. control. tablecolumn; import javafx. scene. control. tableview; import javafx. scene. control. cell. propertyvaluefactory; import javafx. scene. layout. hbox; import javafx. stage. stage; import javafx. util. callback; public class tableviewcellvalue extends application {private tableview <person> table = new tableview <person> (); private final observablelist <person> DATA = fxcollections. observablearraylist (new person ("Jacob", "Smith", "jacob.smith@example.com"), new person ("Isabella", "Johnson", "isabella.johnson@example.com "), new person ("Ethan", "Williams", "ethan.williams@example.com"), new person ("Emma", "Jones", "emma.jones@example.com"), new person ("Michael ", "brown", "michael.brown@example.com"); Final hbox HB = new hbox (); public static void main (string [] ARGs) {launch (ARGs );} @ override public void start (stage) {scene = new scene (new group (); stage. settitle ("Table view sample"); stage. setwidth (450); stage. setheight (550); table. seteditable (true); tablecolumn firstnamecol = new tablecolumn ("first name"); firstnamecol. setcellvaluefactory (New propertyvaluefactory <person, string> ("firstname"); tablecolumn lastnamecol = new tablecolumn ("last name"); lastnamecol. setcellvaluefactory (New propertyvaluefactory <person, string> ("lastname"); tablecolumn emailcol = new tablecolumn ("email"); Final stringproperty sp = new simplestringproperty ("true "); emailcol. setcellvaluefactory (New callback () {@ overridepublic object call (Object arg0) {// sp. set ("true"); Return SP ;}}); table. setitems (data); table. getcolumns (). addall (firstnamecol, lastnamecol, emailcol); // auto-stretch columns. All columns occupy the entire table. setcolumnresizepolicy (tableview. constrained_resize_policy); (Group) scene. getroot ()). getchildren (). addall (table); stage. setscene (scene); stage. show (); SP. setvalue ("false");} public static class person {private final simplestringproperty firstname; private final simplestringproperty lastname; private final simplestringproperty email; private person (string fname, string lname, string email) {This. firstname = new simplestringproperty (fname); this. lastname = new simplestringproperty (lname); this. email = new simplestringproperty (email);} Public String getfirstname () {return firstname. get ();} public void setfirstname (string fname) {firstname. set (fname);} Public String getlastname () {return lastname. get ();} public void setlastname (string fname) {lastname. set (fname);} Public String getemail () {return email. get ();} public void setemail (string fname) {email. set (fname );}}}

Javafx. Scene. Control. tableview constrained_resize_policy: automatically stretch the column. All columns occupy the entire table.

11

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.