Java FXML TableColumn not supporting GregorianCalendar
The GregorianCalendar is not displayed correctly inside the cells of the tablecolumn. When i use Strings, ints and doubles it works fine. When i run the application the cells containing dates show this
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=3600000,..
But i want it to be displayed in year-month-day
public class ProjectenController implements Initializable {
@
FXML
private TableView < Project > TVProject;@
FXML
private TableColumn < Project, Integer > TCID;@
FXML
private TableColumn < Project, String > TCNaam;@
FXML
private TableColumn < Project, GregorianCalendar > TCBeginDatum;@
FXML
private TableColumn < Project, GregorianCalendar > TCEindDatum;@
FXML
private TableColumn < Project, Double > TCAanneemsom;@
FXML
private TableColumn < Project, String > TCGefactureerd;@
FXML
private TableColumn < Project, String > TCBeschrijving;
final ObservableList < Project > data = FXCollections.observableArrayList(
new Project(1, "500", new GregorianCalendar(2015, 1, 23), null, 1000, false, null)
);
@
Override
public void initialize(URL url, ResourceBundle rb) {
TCID.setCellValueFactory(new PropertyValueFactory < > ("ProjectNr"));
TCNaam.setCellValueFactory(new PropertyValueFactory < > ("Naam"));
TCBeginDatum.setCellValueFactory(new PropertyValueFactory < > ("BDatum"));
TCEindDatum.setCellValueFactory(new PropertyValueFactory < > ("EDatum"));
TCAanneemsom.setCellValueFactory(new PropertyValueFactory < > ("Aanneemsom"));
TCGefactureerd.setCellValueFactory(new PropertyValueFactory < > ("Gefactureerd"));
TCBeschrijving.setCellValueFactory(new PropertyValueFactory < > ("Beschrijving"));
TVProject.setItems(data);
}
}
public class Project {
private int ProjectNr;
private String Naam;
private GregorianCalendar BDatum;
private GregorianCalendar EDatum;
double Aanneemsom;
boolean Gefactureerd;
String Beschrijving;
List < Artikel > Artikelen;
List < Activiteit > Activiteiten;
public Project(int projectnr, String naam, GregorianCalendar bdatum,
GregorianCalendar edatum, double aansom, boolean fact, String besc) {
this.ProjectNr = projectnr;
this.Naam = naam;
this.BDatum = bdatum;
this.EDatum = edatum;
this.Aanneemsom = aansom;
this.Gefactureerd = fact;
this.Beschrijving = besc;
}
public int getProjectNr() {
return this.ProjectNr;
}
public String getNaam() {
return this.Naam;
}
public GregorianCalendar getBDatum() {
return this.BDatum;
}
public GregorianCalendar getEDatum() {
return this.EDatum;
}
public double getAanneemsom() {
return this.Aanneemsom;
}
public String getFactureerd() {
if (this.Gefactureerd == true) {
return "Ja";
} else {
return "Nee";
}
}
public String getBeschrijving() {
return this.Beschrijving;
}
}
Create a method returning a String with the formatted date.
In your controller:
@FXML
private TableColumn < Project, String> TCBeginDatum;
...
TCBeginDatum.setCellValueFactory(new PropertyValueFactory < > ("formattedBDatum"));
In your bean:
public String getFormattedBDatum() {
return this.BDatum!=null ? new SimpleDateFormat("yyyy/MM/dd").format(this.BDatum.getTime()) : "";
}
链接地址: http://www.djcxy.com/p/6256.html