将JavaFx 2和Netbeans IDE 8.0与Java 8一起使用。
我从FileMaker
数据库中提取数据并将其添加为" Ticket"对象为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类,有我的setter / getters等:
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
(&#34; ticketData&#34;此处),以保存项目,每列都有与票证类相关联的CellValueFactory
。
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
仍为空白。
有什么建议吗?我错过了什么吗?我不知所措。
答案 0 :(得分:0)
PropertyValueFactory<>("TicketType")
应为ticketType,请注意小写。所有领域都相同。
http://docs.oracle.com/javafx/2/api/javafx/scene/control/cell/PropertyValueFactory.html