I am currently using PropertyValueFactory but I am trying to convert to lambda expressions. There are two reasons I want to do this. One is to learn to use lambda expressions. The other is to get away from having to use the string to define the property.
I have also made a simple program to test this using Netscape and it doesn't work there either. Actually on Netscape it is even worse - the getValue method does not appear to exist when I use Netscape so I am not even able to enter the lambda expression for the SimpleStringProperty.
I am getting similar error messages, and I'm wondering if what you are attempting to do is similar to what I want to do. I am a newbie to FX, and unfamiliar with CellValueFactory, but perhaps you can help.
What I want to do is create a dynamic table, one that does not know in advance how many columns it has. (I'm actually using as a springboard for my understanding a program I found here at the Ranch.) What I am trying to do is create a sort of Extremely-Mini-Spreadsheet for doing statistical analysis. The TableView would be the vehicle for data entry; in addition the program will read data from files and populate the TableView. My idea thus far has been to try to create an array of SimpleStringProperties for the data. (Strings b/c of the need to parse the data; some data will be Yes/No, Blue/Green/Red, etc.) My Netbeans IDE does not complain when I ask for such an array, and I even get column headings correctly. However, when I try to get() and set() values, I get tsk-tsks about incompatible return types. I believe the problem I am trying to get around is that the property name seems to be hard-coded as part of the get/set statements. In order to try to get the syntax correct, I am modifying the Ranch contribution. Here is where I'm running into incompatibility complaints. (Apologies, I don't know how to insert the code with those nifty numbers.)
//Create a new table show details of the selected item
Record selectedRecord = (Record) tblView.getItems().get(selectdIndex);
new SubRecord("ID", selectedRecord.getDaInteger(0)), // <--------------------------
new SubRecord("Monday", selectedRecord.getValue_0()),
What I THINK I want to do is have the "selectedRecord" part somehow be a variable rather than hard-wired. Would CellValueFactory somehow let me do this?
I am not sure what you are trying to do or what your exact problem is. But let me review what I understand about setCellValueFactory.
setCellValueFactory is used to associate a column in a TableView with a property of a class that contains the data to be displayed in the TableView's column. An ObservableList will then be created containing several instances of the class, each containing data. A row in the table will be created for each instance of the class.
For example, here is a class containing several properties.
Now that the class is created, instances of the class are created and placed into an ObservableList. Here is an example of this:
This ObservableList has two entries so the TableView will have two rows.
The last thing to do is to associate the columns in the TableView with properties in the class in the ObservableList. That is done with the setCellValueFactory method. There are two ways to use this method.
Method 1 (the old method)
This informs the TableViewColumn that it will acquire the data for the column named "colStudy" from the property named "parameter". Note that rather than hardcoding the property name, you could also put a string variable in as follows:
This would allow you to dynamically name the property.
Method 2 (new method using lambda expression)
This method allows you to assign the column to the property in a more direct manner without using a fixed string. Note that in the case above, parameterProperty is a SimpleStringProperty. Had the property been a SimpleIntegerProperty, you would have to modify the statement by adding the AsObject method as follows:
I am not sure I am answering your question, but I hope I have shed some light on the purpose of setCellValueFactory. Here is a link to an article that explains this procedure a bit further.
This is very helpful! Thank you. The Ranch has been very helpful with several Java and FX problems I've encountered along the way with this project. In general, part of what I am trying to do is write a scatterplot program, the kind of thing you see in Algebra I. (Technically it is part of a larger statistics project.) I want to be able to read in data from a CSV file, show the results in an editable TableView for possible change, and plot the points. I also want to be able to to click and drag on the x- and y-axis to move it as desired. The last problem I have to solve is the TableView part.
I am hoping to "pay back" the Ranch and post this when I get it done, thinking that others may have similar problems.