将JavaFx 2和Netbeans IDE 8.0与Java 8结合使用。我正在从FileMaker
数据库中提取数据,并将其作为“票证”对象添加到observableArrayList
(在此称为“行”)对象。然后,我将该列表传递给表以显示已找到的内容。我已observableArrayList
填充,但无法使其显示在表格中。
我有在FXML中建立的表格视图:
<TableView fx:id="ticketData" layoutX="-3.0" layoutY="351.0" prefHeight="203.0" prefWidth="554.0">
<columns>
<TableColumn fx:id="ticket" editable="false" prefWidth="59.0" text="Ticket" />
<TableColumn fx:id="dates" prefWidth="72.0" text="Date(s)" />
<TableColumn fx:id="files" editable="false" prefWidth="114.0" text="File(s) Found" />
<TableColumn fx:id="notes" prefWidth="297.0" text="Notes" />
</columns>
</TableView>
我的Java类具有我的设置器/获取器等:
public class Ticket
{
private SimpleStringProperty ticketType;
private SimpleObjectProperty<Date> executionDate;
private SimpleBooleanProperty gotFile;
private SimpleStringProperty statusMessage;
public Ticket(String tt, Date done, boolean gf, String stat)
{
this.ticketType = new SimpleStringProperty (tt);
this.executionDate = new SimpleObjectProperty<Date>(done) {};
this.gotFile = new SimpleBooleanProperty(gf);
this.statusMessage = new SimpleStringProperty(stat);
}
public String getTicketType() {
return ticketType.get();
}
public void setTicketType(String tt) {
ticketProperty().set(tt);
}
public StringProperty ticketProperty() {
if (ticketType == null) ticketType = new SimpleStringProperty(this, "ticketType");
return ticketType;
}
public Date getExecutionDate() {
return executionDate.get();
}
public void setExecutionDate(Date done) {
executionDate.set(done);
}
public SimpleObjectProperty dateProperty() {
if (executionDate == null) executionDate = new SimpleObjectProperty(this, "executionDate");
return executionDate;
}
public boolean getGotFile(){
return gotFile.get();
}
public void setGotFile(boolean gf){
gotFile.set(gf);
}
public SimpleBooleanProperty gotProperty() {
if (gotFile == null) gotFile = new SimpleBooleanProperty(this, "gotFile");
return gotFile;
}
public String getStatusMessage() {
return statusMessage.get();
}
public void setStatusMessage(String stat) {
statusMessage.set(stat);
}
public StringProperty statusProperty() {
if (statusMessage == null) statusMessage = new SimpleStringProperty(this, "statusMessage");
return statusMessage;
}
}
用于从以下位置收集resultset
我需要的数据的方法FileMaker
:
public void accumulate(String type, Date essential, boolean got, String msg)
{
Ticket ticket;
ticket = new Ticket(type, essential, got, msg);
row.add(ticket);
}
在完成对所需内容的搜索之后,然后在控制器中,设置我的tableview
“ ticketData”(此处为“ ticketData”),以保存项目,每一列都具有一个CellValueFactory
与Ticket类相关的列。
ticketData = new TableView();
ticket.setCellFactory(TextFieldTableCell.forTableColumn());
ticket.setCellValueFactory(
new PropertyValueFactory<>("ticketType"));
dates.setCellFactory(TextFieldTableCell.forTableColumn());
dates.setCellValueFactory(
new PropertyValueFactory<>("executionDate"));
files.setCellFactory(TextFieldTableCell.forTableColumn());
files.setCellValueFactory(
new PropertyValueFactory<>("gotFile"));
notes.setCellFactory(TextFieldTableCell.forTableColumn());
notes.setCellValueFactory(
new PropertyValueFactory<>("statusMessage"));
ticketData.getColumns().addAll(ticket,dates,files,notes);
//System.out.println(Arrays.deepToString(row.toArray()));
ticketData.setItems(row);
我可以在上打印observableArrayList
并查看其中的条目,但是tableview
仍然空白。
有什么建议?我错过了什么吗?我很茫然。
PropertyValueFactory<>("TicketType")
应该是ticketType,请注意小写。所有字段均相同。
http://docs.oracle.com/javafx/2/api/javafx/scene/control/cell/PropertyValueFactory.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句