Iām using JavaFX 8 and JDK 1.8.0_77 in IntelliJ with SceneBuilder. I created the Message Center GUI with SceneBuilder. I have a TableView with five columns, Start Date, End Date, Message, Category and Status. The values are entered via controls and saved in the Message Object when the Add button is clicked. The Message object is added to the msgTableView with msgTableView.getItems().add(message).
The problem is as I add a message object to the bottom row, all the previous rows change to the last row; the number of rows is correct but all the rows are the same.
My Message object code:
public class Message implements Serializable {
public static LocalDate startDate = LocalDate.now();
public static LocalDate endDate = LocalDate.now();
public static String newMsg;
public static String status;
public static String category;
public void Messages(LocalDate StartDate, LocalDate EndDate, String NewMsg, String Status, String Category){
this.startDate = StartDate;
this.endDate = EndDate;
this.newMsg = NewMsg;
this.status = Status;
this.category = Category;
}
// --------------Getters and Setters----------------------------
public LocalDate getStartDate() {
return startDate;
}
public void setStartDate(LocalDate startDate) {
this.startDate = startDate;
}
public LocalDate getEndDate() {
return endDate;
}
public void setEndDate(LocalDate endDate) {
this.endDate = endDate;
}
public String getNewMsg() {
return newMsg;
}
public void setNewMsg(String newMsg) {
this.newMsg = newMsg;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getCategory() {
return category;
}
public void setCategory(String type) {
this.category = type;
}
The critical Controller code is:
// TableView --------------------------------------------------------------------------------
@FXML
private TableView<Message> msgTableView;
@FXML
private TableColumn<Message, LocalDate> StartDateTableCol;
@FXML
private TableColumn<Message, LocalDate> EndDateTableCol;
@FXML
private TableColumn<Message, String> MessageTableCol;
@FXML
private TableColumn<Message, String> CategoryTableCol;
@FXML
private TableColumn<Message, String> StatusTableCol;
@FXML
private DatePicker startDatePicker;
@FXML
private DatePicker endDatePicker;
@FXML
private TextField msgTextField;
@FXML
private ComboBox categoryComboBox;
@FXML
private Button addButton;
@FXML
private Button deleteButton;
@FXML
private Button editButton;
public void saveLine() {
Message message = new Message();
message.setStartDate(startDatePicker.getValue());
message.setEndDate(endDatePicker.getValue());
message.setNewMsg(msgTextField.getText());
message.setStatus("active");
message.setCategory(categoryComboBox.getValue().toString());
msgTableView.getItems().add(message);
clearLine();
}
public void clearLine() {
System.out.println( "\nEntered clearAll() " );
startDatePicker.setValue(null);
endDatePicker.setValue(null);
msgTextField.clear();
categoryComboBox.setValue("Category");
}