JavaFx TableView cellFactory memory overhead - javafx

My question is related to TableView from JavaFx.
JavaFx recommends using Properties for storing values which are going to be shown in the table ( SimpleSttringProperty, etc. ) like in the example below.
Isn't this an memory overhead for Java ( creating another object for each cell ) ?
I am going to use the TableView to show more then 10.000 rows from the database.
Isn't there a way to avoid this, and simply work as Swing did earlier ?
Can't TableView get only the value to represent ?
For all solutions I found an ObservableValue is required for each cell, which may require a lot of memory.
TableColumn<Person,String> firstNameCol = new TableColumn<Person,String>("First Name");
firstNameCol.setCellValueFactory( element -> element.getValue().firstName );
or
firstNameCol.setCellValueFactory( new PropertyValueFactory<Person, String>("firstName"));
public static class Person {
public 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);
}

You are not required to use property in your model. Here is an example
public class Person {
private String firstName;
private String lastName;
private String email;
public Person() {
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
just create the property when you need it.
firstNameCol.setCellValueFactory(cdf -> new SimpleStringProperty(cdf.getValue().getFirstName()));

Related

java.lang.NoSuchMethodException Gluon Connect

please i get this errror on logcat when i use restclient to get a list. it works on desktop just after deploymnet to android
java.lang.NoSuchMethodException: ...dto.Meeting.()
its pops up more than the number of record i have in my list
WARNING: Failed to create object of type class .Meeting from the following json object {"id":1,"topic":"leksyde","description":"123e4","location":"7623","longitude":"45","latitude":"10","category":null,"datetime":"9839823"}
primary.setShowTransitionFactory(BounceInRightTransition::new);
RestClient restClient = RestClient.create()
.method("GET")
.host(LISTOFMEETINGS);
// create a custom Converter that is able to parse the response into a list of objects
InputStreamIterableInputConverter<Meeting> converter = new ItemsIterableInputConverter<>(Meeting.class);
// retrieve a list from the DataProvider
GluonObservableList<Meeting> data = DataProvider.retrieveList(restClient.createListDataReader(converter));
data.initializedProperty().addListener((obs, ov, nv) -> {
if (nv) {
for (Meeting meet: data) {
meetingslv.setItems(meet);
}
}
});
meeting.java
public class Meeting {
private IntegerProperty id = new SimpleIntegerProperty();
private StringProperty topic = new SimpleStringProperty();
private StringProperty description = new SimpleStringProperty();
private StringProperty location = new SimpleStringProperty();
private StringProperty longitude = new SimpleStringProperty();
private StringProperty latitude = new SimpleStringProperty();
private StringProperty datetime = new SimpleStringProperty();
private StringProperty category = new SimpleStringProperty();
public Meeting() {
}
public Meeting(int id, String topic, String description, String location, String longitude, String latitude, String datetime, String category) {
this.id = new SimpleIntegerProperty(id);;
this.topic = new SimpleStringProperty(topic);
this.description = new SimpleStringProperty(description);
this.location = new SimpleStringProperty(location) ;
this.longitude = new SimpleStringProperty(longitude);
this.latitude = new SimpleStringProperty(latitude);
this.datetime = new SimpleStringProperty(datetime);
this.category = new SimpleStringProperty(category);
}
public int getId() {
return id.get();
}
public IntegerProperty IdProperty() {
return id;
}
public void setId(int id) {
this.id.set(id);
}
public String getTopic() {
return topic.get();
}
public StringProperty TopicProperty() {
return topic;
}
public void setTopic(String id) {
this.topic.set(id);
}
public String getDescription() {
return description.get();
}
public StringProperty DescriptionProperty() {
return description;
}
public void setDescription(String id) {
this.description.set(id);
}
public String getLocation() {
return location.get();
}
public StringProperty LocationProperty() {
return location;
}
public void setLocation(String id) {
this.location.set(id);
}
public String getLongitude() {
return longitude.get();
}
public StringProperty LongitudeProperty() {
return longitude;
}
public void setLongitude(String id) {
this.longitude.set(id);
}
public String getLatitude() {
return latitude.get();
}
public StringProperty LatitudeProperty() {
return latitude;
}
public void setLatitude(String id) {
this.latitude.set(id);
}
public String getDatetime() {
return datetime.get();
}
public StringProperty DatetimeProperty() {
return datetime;
}
public void setDatetime(String id) {
this.datetime.set(id);
}
public String getCategory() {
return category.get();
}
public StringProperty CategoryProperty() {
return category;
}
public void setCategory(String id) {
this.category.set(id);
}
}
this is the list i am trying to parse to the listview [enter link description here]1

No setter/field found on class but variable names are correct

I am trying to implement a star rating system using Firebase realtime database and I get the following error:
No setter/field for rating found on class com.andrea.uncut.ui.Model.Post
I know this can happen when variables are not named the same as in the database but in this case they are:
public class Post {
private String postID;
private String postImage;
private float rating;
private String title;
private String description;
private String publisher;
public Post(String postID, String postImage, float rating, String title, String description, String publisher) {
this.postID = postID;
this.postImage = postImage;
this.rating = rating;
this.title = title;
this.description = description;
this.publisher = publisher;
}
public Post() {
}
public String getPostid() {
return postID;
}
public void setPostid(String postID) {
this.postID = postID;
}
public String getPostImage() {
return postImage;
}
public void setPostImage(String postImage) {
this.postImage = postImage;
}
public float getRatingScore() { return rating; }
public void setRatingScore(float rating) {
this.rating = rating;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
}
All the other variables work fine so could it be anything related to the type being float?
getRatingScore and setRatingScore would be used for a property called ratingScore.
Your property is called rating, so it would need to be getRating and setRating.
The private internal properties have nothing to do with how Firebase sees them when setting data on the model class.
Plus, postID should be getPostID and setPostID for consistency.

JavaFx, application don't add information

I am doing program similar on ContactList, but when I try to add information, I can't see my information. But if I do nine clicks, I can see scrolling.
I have my work file, end prtsc fxml file below.
#FXML
private void initialize() throws IOException {
iniData();
id.setCellValueFactory(new PropertyValueFactory<Work, Integer>("id"));
Fname.setCellValueFactory(new PropertyValueFactory<Work, String>("fname"));
Lname.setCellValueFactory(new PropertyValueFactory<Work, String>("lname"));
Phone.setCellValueFactory(new PropertyValueFactory<Work, String>("phone"));
Email.setCellValueFactory(new PropertyValueFactory<Work, String>("email"));
table.setItems(arr);
addName.setPromptText("fname");
addName.setMaxWidth(Fname.getPrefWidth());
addLName.setPromptText("lname");
addLName.setMaxWidth(Lname.getPrefWidth());
addPhone.setPromptText("phone");
addPhone.setMaxWidth(Phone.getPrefWidth());
addEmail.setPromptText("email");
addEmail.setMaxWidth(Email.getPrefWidth());
btn01.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
arr.add(new Work(addName.getText(),
addLName.getText(), addPhone.getText(), addEmail.getText()));
} } ); }
public void iniData() throws IOException {
arr.add(new Work(1, "Alex", "qwerty", "33333","alex#mail.com"));
arr.add(new Work(2, "Bob", "dsfsdfw","0987432", "bob#mail.com"));
arr.add(new Work(3, "Jeck", "dsfdsfwe","345743", "Jeck#mail.com"));
arr.add(new Work(4, "Mike", "iueern","32456", "mike#mail.com"));
arr.add(new Work(5, "colin", "woeirn","12233455", "colin#mail.com"));
}}
My Work java file.
public class Work implements Serializable{
private Integer id;
private String Fname;
private String Lname;
private String Phone;
private String Email;
private String addFname;
private String addLname;
private String addPhone;
private String addEmail;
public Work(Integer id, String fname, String lname, String phone, String email) {
this.id = id;
Fname = fname;
Lname = lname;
Phone = phone;
Email = email;
}
public Work(String addFname, String addLname, String addPhone, String addEmail) {
this.addFname = addFname;
this.addLname = addLname;
this.addPhone = addPhone;
this.addEmail = addEmail;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFname() {
return Fname;
}
public void setFname(String fname) {
Fname = fname;
}
public String getLname() {
return Lname;
}
public void setLname(String lname) {
Lname = lname;
}
public String getPhone() {
return Phone;
}
public void setPhone(String phone) {
Phone = phone;
}
public String getEmail() {
return Email;
}
public void setEmail(String email) {
Email = email;
}
public String getAddFname() {
return addFname;
}
public void setAddFname(String addFname) {
this.addFname = addFname;
}
public String getAddLname() {
return addLname;
}
public void setAddLname(String addLname) {
this.addLname = addLname;
}
public String getAddPhone() {
return addPhone;
}
public void setAddPhone(String addPhone) {
this.addPhone = addPhone;
}
public String getAddEmail() {
return addEmail;
}
public void setAddEmail(String addEmail) {
this.addEmail = addEmail;
}
}
this is the link to view fxml file
As your not using properties in your Work class you have to set the cell like
FName.setCellValueFactory(new Callback<CellDataFeatures<Work, String>, ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<Work, String> p) {
return new ReadOnlyObjectWrapper(p.getValue().getFname());
}
});
As an alternate you could use properties but aus they are not serializable you have to override the functions for reading and writing object as discribed here

Add Property to ControlsFX PropertySheet

I am creating a PropertySheet and I want to add a Property to the sheet. The problem is, what happens if the value of the property changes, the PropertySheet needs to update to reflect those changes. How would I do this?
import java.util.Map;
import javafx.beans.property.Property;
import org.controlsfx.control.PropertySheet;
public class PropertyItem implements PropertySheet.Item {
private Map<String, Property> map;
private String key;
private String name;
private String description;
PropertyItem(Map<String, Property> map, String key, String name, String description){
this.map = map;
this.key = key;
this.name = name;
this.description = description;
}
#Override
public String getCategory() {
return null;
}
#Override
public String getDescription() {
return description;
}
#Override
public String getName() {
return name;
}
#Override
public Class<?> getType() {
return map.get(key).getValue().getClass();
}
#Override
public Object getValue() {
return map.get(key).getValue();
}
#Override
public void setValue(Object arg0) {
map.get(key).setValue(arg0);
}
}
This is probably too late but anyway...
The property editor uses the following method from PropetySheet.Item interface to listen to value changes.
optional<ObservableValue<? extends Object>> getObservableValue();
You need to implement this method on your PropertyItem class.

sort items by date joined in tableview JavaFX

I have a tableview which there are some items in it with date joined, date joined form is dd nameOfMonth, yyy, how can i sort my items by date joined?
Here is the part of code for my item class:
public static class Person1 {
private StringProperty firstName;
private StringProperty joined;
public Person1(String firstName, String joined) {
this.firstName = new SimpleStringProperty(firstName);
this.joined = new SimpleStringProperty(joined);
}
public StringProperty firstNameProperty() {
return firstName;
}
public StringProperty joinedProperty(){
return joined;
}
}

Resources