setItems() 后无法在 tableview 的单元格中看到数据
Cant see data in cells in tableview after setItems()
我正在尝试将我的测试 ObservableList 数据放入我使用场景生成器制作的 JavaFX TableView 中,但是当我使用 setItems() 时,我可以看到有 5 行数据,但该行中的单元格不包含任何数据或至少我看不到
private final ObservableList<tblQuery> data =
FXCollections.observableArrayList(
new tblQuery("Jacob", "Smith", "jacob.smith@example.com"),
//4 more rows
);
private javafx.scene.control.TableView<tblQuery> tableview;
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml"));
Parent root = loader.load();
tableview = (TableView) loader.getNamespace().get("tabQuery");
primaryStage.setTitle("Cycle reloader");
primaryStage.setResizable(false);
primaryStage.setScene(new Scene(root));
tableview.setEditable(true);
TableColumn coID = new TableColumn("Cycle№");
coID.setMinWidth(80);
coID.setCellValueFactory(
new PropertyValueFactory<tblQuery, String>("id"));
//workflow and date columns, same as id column
tableview.setItems(data);
tableview.getColumns().addAll(coID, colWorkflow, colDate);
primaryStage.show();
}
public class tblQuery {
private final SimpleStringProperty id;
private final SimpleStringProperty workflow;
private final SimpleStringProperty date;
private tblQuery(String id, String workflow, String date) {
this.id = new SimpleStringProperty(id);
this.workflow = new SimpleStringProperty(workflow);
this.date = new SimpleStringProperty(date);
}
public String getID() {
return id.get();
}
public void setID(String fName) {
id.set(fName);
}
public String getWorkflow() {
return workflow.get();
}
public void setWorkflow(String fName) {
workflow.set(fName);
}
public String getDate() {
return date.get();
}
public void setDate(String fName) {
date.set(fName);
}
}
我只能看到:
我可以 select selected 上面的任何行,但不能用 selection
getID()
拼写错误。为了遵循 bean 约定,它应该是 getId()
。
这是修改后的工作示例。
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
public class TableApp extends Application {
private final ObservableList<TblQuery> data =
FXCollections.observableArrayList(
new TblQuery("Jacob", "Smith", "jacob.smith@example.com"),
new TblQuery("Isabella", "Johnson", "isabella.johnson@example.com"),
new TblQuery("Ethan", "Williams", "ethan.williams@example.com"),
new TblQuery("Emma", "Jones", "emma.jones@example.com"),
new TblQuery("Michael", "Brown", "michael.brown@example.com")
);
private javafx.scene.control.TableView<TblQuery> tableview = new TableView<>();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Cycle reloader");
primaryStage.setResizable(false);
primaryStage.setScene(new Scene(tableview));
tableview.setEditable(true);
TableColumn idCol = new TableColumn("What");
idCol.setMinWidth(80);
idCol.setCellValueFactory(
new PropertyValueFactory<TblQuery, String>("id"));
TableColumn workflowCol = new TableColumn("Workflow name");
workflowCol.setMinWidth(236);
workflowCol.setCellValueFactory(
new PropertyValueFactory<TblQuery, String>("workflow"));
TableColumn dateCol = new TableColumn("AS OF DAY");
dateCol.setMinWidth(80);
dateCol.setCellValueFactory(
new PropertyValueFactory<TblQuery, String>("date"));
tableview.setItems(data);
tableview.getColumns().addAll(idCol, workflowCol, dateCol);
primaryStage.show();
}
}
import javafx.beans.property.SimpleStringProperty;
public class TblQuery {
private final SimpleStringProperty idProperty = new SimpleStringProperty();
private final SimpleStringProperty workflowProperty = new SimpleStringProperty();
private final SimpleStringProperty dateProperty = new SimpleStringProperty();
public TblQuery(String id, String workflow, String date) {
this.idProperty.set(id);
this.workflowProperty.set(workflow);
this.dateProperty.set(date);
}
public void setId(String id) {
this.idProperty.set(id);
}
public String getId() {
return idProperty.get();
}
public String getWorkflow() {
return workflowProperty.get();
}
public void setWorkflow(String workflow) {
this.workflowProperty.set(workflow);
}
public String getDate() {
return dateProperty.get();
}
public void setDate(String date) {
this.dateProperty.set(date);
}
}
我正在尝试将我的测试 ObservableList 数据放入我使用场景生成器制作的 JavaFX TableView 中,但是当我使用 setItems() 时,我可以看到有 5 行数据,但该行中的单元格不包含任何数据或至少我看不到
private final ObservableList<tblQuery> data =
FXCollections.observableArrayList(
new tblQuery("Jacob", "Smith", "jacob.smith@example.com"),
//4 more rows
);
private javafx.scene.control.TableView<tblQuery> tableview;
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml"));
Parent root = loader.load();
tableview = (TableView) loader.getNamespace().get("tabQuery");
primaryStage.setTitle("Cycle reloader");
primaryStage.setResizable(false);
primaryStage.setScene(new Scene(root));
tableview.setEditable(true);
TableColumn coID = new TableColumn("Cycle№");
coID.setMinWidth(80);
coID.setCellValueFactory(
new PropertyValueFactory<tblQuery, String>("id"));
//workflow and date columns, same as id column
tableview.setItems(data);
tableview.getColumns().addAll(coID, colWorkflow, colDate);
primaryStage.show();
}
public class tblQuery {
private final SimpleStringProperty id;
private final SimpleStringProperty workflow;
private final SimpleStringProperty date;
private tblQuery(String id, String workflow, String date) {
this.id = new SimpleStringProperty(id);
this.workflow = new SimpleStringProperty(workflow);
this.date = new SimpleStringProperty(date);
}
public String getID() {
return id.get();
}
public void setID(String fName) {
id.set(fName);
}
public String getWorkflow() {
return workflow.get();
}
public void setWorkflow(String fName) {
workflow.set(fName);
}
public String getDate() {
return date.get();
}
public void setDate(String fName) {
date.set(fName);
}
}
我只能看到:
我可以 select selected 上面的任何行,但不能用 selection
getID()
拼写错误。为了遵循 bean 约定,它应该是 getId()
。
这是修改后的工作示例。
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
public class TableApp extends Application {
private final ObservableList<TblQuery> data =
FXCollections.observableArrayList(
new TblQuery("Jacob", "Smith", "jacob.smith@example.com"),
new TblQuery("Isabella", "Johnson", "isabella.johnson@example.com"),
new TblQuery("Ethan", "Williams", "ethan.williams@example.com"),
new TblQuery("Emma", "Jones", "emma.jones@example.com"),
new TblQuery("Michael", "Brown", "michael.brown@example.com")
);
private javafx.scene.control.TableView<TblQuery> tableview = new TableView<>();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Cycle reloader");
primaryStage.setResizable(false);
primaryStage.setScene(new Scene(tableview));
tableview.setEditable(true);
TableColumn idCol = new TableColumn("What");
idCol.setMinWidth(80);
idCol.setCellValueFactory(
new PropertyValueFactory<TblQuery, String>("id"));
TableColumn workflowCol = new TableColumn("Workflow name");
workflowCol.setMinWidth(236);
workflowCol.setCellValueFactory(
new PropertyValueFactory<TblQuery, String>("workflow"));
TableColumn dateCol = new TableColumn("AS OF DAY");
dateCol.setMinWidth(80);
dateCol.setCellValueFactory(
new PropertyValueFactory<TblQuery, String>("date"));
tableview.setItems(data);
tableview.getColumns().addAll(idCol, workflowCol, dateCol);
primaryStage.show();
}
}
import javafx.beans.property.SimpleStringProperty;
public class TblQuery {
private final SimpleStringProperty idProperty = new SimpleStringProperty();
private final SimpleStringProperty workflowProperty = new SimpleStringProperty();
private final SimpleStringProperty dateProperty = new SimpleStringProperty();
public TblQuery(String id, String workflow, String date) {
this.idProperty.set(id);
this.workflowProperty.set(workflow);
this.dateProperty.set(date);
}
public void setId(String id) {
this.idProperty.set(id);
}
public String getId() {
return idProperty.get();
}
public String getWorkflow() {
return workflowProperty.get();
}
public void setWorkflow(String workflow) {
this.workflowProperty.set(workflow);
}
public String getDate() {
return dateProperty.get();
}
public void setDate(String date) {
this.dateProperty.set(date);
}
}