JavaFX and Scene Builder Course - IntelliJ #30: TableView and TableColumn

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey it's suffering student here and today i'm going to showcase how to use the table view with scene builder and java effects using intellij and scene builder as mentioned so first of all the table view is just a very simple view that kind of looks like an excel document where we are able to create columns which we in the code are able to add elements which will be showcased in our rows and our table view contains table columns and let's just change the name of our column so let's first maybe have a name and then we are gonna have r [Music] let's just go with h and maybe add another one and just call it animal i don't know it doesn't really matter on this point we just don't experiment stuff and then i would go and give each of my table columns the same id as the name of my column so i'm just going to call my name column for name h column h and animal column animal save and let's also give the table view the id off let's just call it table in this case just to make it very simple i've gone to view show sample control skeleton and copy all of my controller example into my controller there we go and let's actually just try running it to see it works and there we go so now what we actually need to do is tell the table view what we're going to be inputting into our table and what we're going to be inputting into our specific columns so let's create a new object or a new class first which i am just going to call a user and then for each user we're going to match our attributes for the columns we just created so i will also have a name h and animal column so let's just have a private string name uh private let's see what we add an eight let's make an integer into h and um private string animal which is just going to be the animal type name doesn't really matter and then i will add a constructor and i'll use the simple shortcut of doing alt insert where i can create a constructor containing all my attributes and let's just also create some getters for each of my attributes so now what we need to do is inside a controller first tell that our table need to contain users we will have our name column containing and strings so first which language object is coming from and then what type it's going to be and again with the h again is the user it's an ins and out animal is also from our user and that is a string then we are going to implement initializable which allows us to implement initialize method and actually made a mistake our tables columns actually don't take an integer we need to give it an integer because it is only taking an object where our integer is a symbol variable we need to be complex types where we need to get the integer inside initialize we will then tell our our column each column what it's going to take from our objects we're gonna be creating for the users so we're gonna have a name where we're gonna set cell value factory where we will have a new property value factory taking in the object again at the type so we're gonna have our user and our string we're then going to tell it specifically from our user which of our attributes will it be and it is going to be our name attribute and we're then going to do this for all of our columns so i'll just copy this and set it for our age as well where we then as well is going to use an integer instead of our string and it's of course going to be our h and our name is going gonna be animal and we're gonna change to the animal attribute so now let's just create some objects of our user and i'm gonna put him inside an observable list because that's what our table view is going to take as an input so i would do observable list containing a user i'm just going to call it list and we're going to set it as a fx collections dot observable arraylist and i'm just gonna give it some input so inside here are parentheses we can actually just create our new user so let's first give it a name daniel add an h of 20 and animal for dog which should also be a string ah let's have another one we're gonna have anna she's gonna be 21 i'm gonna give her a cat let's make it consistent and maybe add a last one which we are just gonna call mark just add another random age 22 and let's be a bit creative and give him the bird so now what we can very simply do is we can simply take our table dot set items and just simply give it a list so now if you run the program again because this is inside initialized so when we start our program we're gonna set the constraints for our columns and we're then gonna add our observable list where we added a few users and add them to our table so let's run the program and as you can see we now have a table view where we have our names our age and the animal and it's just simply the information we added inside our initialize or the properties we added and then some information we added inside of our observable list and just simply added it to our table so that's pretty much a very simple example of how we are able to create a table inside scene builder adding table columns giving them some ids defining under the id the object type we're going to be inputting and the object type it's going to be containing and then simply setting some constraints using the property value factory the value of x3 again constraining that it is a user user object with the string information and then the name attribute from the user and that gives our program this pretty nice result so if you enjoyed this video please leave a like and subscribe and i wish you all a wonderful day
Info
Channel: Random code
Views: 4,412
Rating: undefined out of 5
Keywords: TableView, TableColumn, TableView and TableColumn, JavaFX, Scene Builder, JavaFX Scene Builder, Tutorial, JavaFX Scene Builder Tutorial, sql, mysql, tableview, TableView JavaFX, TableColumn JavaFX, Java, java, javafx, programming knowledge, database, JavaFX TableView, JavaFX TableColumn, javafx tableview design, tableview javafx tutorial javafx tableview database, JavaFX and Scene Builder Course - IntelliJ #30: TableView and TableColumn, javafx tableview scroll, uitableview
Id: fnU1AlyuguE
Channel Id: undefined
Length: 8min 45sec (525 seconds)
Published: Sat Mar 27 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.