Java FXML TableColumn不支持GregorianCalendar
GregorianCalendar在表列的单元格内无法正确显示。 当我使用字符串,整数和双打时,它工作正常。 当我运行应用程序时,包含日期的单元显示了这一点
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=3600000,..
但我希望它在年 - 月 - 日显示
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;
}
}
创建一个方法返回格式化日期的字符串。
在你的控制器中:
@FXML
private TableColumn < Project, String> TCBeginDatum;
...
TCBeginDatum.setCellValueFactory(new PropertyValueFactory < > ("formattedBDatum"));
在你的bean中:
public String getFormattedBDatum() {
return this.BDatum!=null ? new SimpleDateFormat("yyyy/MM/dd").format(this.BDatum.getTime()) : "";
}
链接地址: http://www.djcxy.com/p/6255.html
上一篇: Java FXML TableColumn not supporting GregorianCalendar
下一篇: Java Weird System output for GregorianCalendar arraylist