Java FXML TableColumn 不支持 GregorianCalendar

Java FXML TableColumn not supporting 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()) : "";
}