javafx tableview tablemodel连接
javafx tableview tablemodel connection
我想将我的 javafx table 视图连接到我的 table 模型的数据以显示在视图中。
我收到一个错误:
incompatible types: WorkoutTableModel cannot be converted to ObservableList
非常感谢任何见解或建议。
我在尝试转换为 ObservableList 时也遇到错误:
incompatible types: inference variable E has incompatible bounds
equality constraints: Workout
lower bounds: WorkoutTableModel
where E is a type-variable:
E extends Object declared in method <E>observableArrayList(E...)
The type of <E>observableArrayList(E...) is erroneous
where E is a type-variable:
E extends Object declared in method <E>observableArrayList(E...)
谢谢!
table 型号:
package myworkouts.presentation;
import myworkouts.domain.*;
import java.util.*;
import javax.swing.table.AbstractTableModel;
public class WorkoutTableModel extends AbstractTableModel {
private String[] columnNames = {"Date", "Route", "Distance", "Time"};
private List<Workout> workouts = new LinkedList<Workout>();
public void setWorkouts(List<Workout> workouts) {
this.workouts = workouts;
}
@Override
public int getRowCount() {
return workouts.size();
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int row, int column) {
Workout workout = workouts.get(row);
switch (column) {
case 0:
return workout.getDate();
case 1:
return workout.getRoute();
case 2:
return workout.getDistance();
case 3:
return workout.getTime();
}
return "";
}
@Override
public String getColumnName(int column) {
return columnNames[column];
}
}
mainUI 片段:
public class MainUI extends Application {
private Account account = null;
private WorkoutTableModel model = new WorkoutTableModel();
final ObservableList<Workout> data = FXCollections.observableArrayList(model);
public void setAccount(Account account) {
this.account = account;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Workout CRUD form JavaFX Application");
TableView workoutsTbl = new TableView();
workoutsTbl.setEditable(true);
workoutsTbl.setItems(model);
// Add workoutsTbl header
Text headerLabel = new Text("Workouts");
headerLabel.getStyleClass().add("header");
// add workoutsTbl column labels
TableColumn dateCol = new TableColumn("Date");
TableColumn routeCol = new TableColumn("Route");
TableColumn distanceCol = new TableColumn("Distance");
TableColumn timeCol = new TableColumn("Time");
workoutsTbl.getColumns().addAll(dateCol, routeCol, distanceCol, timeCol);
workoutsTbl.autosize();
VBox vbox = new VBox(10);
vbox.setSpacing(5);
vbox.setPadding(new Insets(10,5,5,10));
// Create the registration form grid pane
GridPane gridPane = createWorkoutsFormPane();
//gridPane.add(workoutsTbl,1,10,2,5);
vbox.getChildren().addAll(headerLabel,workoutsTbl,gridPane);
// Add UI controls to the registration form grid pane
addUIControls(gridPane);
// Create a scene with registration form grid pane as the root node
Scene scene = new Scene(vbox, 520, 500);
// Set the scene in primary stage
primaryStage.setScene(scene);
scene.getStylesheets().add
(MainUI.class.getResource("Login.css").toExternalForm());
primaryStage.show();
}
最终 ObservableList 数据 = FXCollections.observableArrayList(模型);
Swing AbstractTableModel 不是 List-type 东西。看看它的声明,看看它实现了什么。这不是李斯特。
我想将我的 javafx table 视图连接到我的 table 模型的数据以显示在视图中。
我收到一个错误:
incompatible types: WorkoutTableModel cannot be converted to ObservableList
非常感谢任何见解或建议。 我在尝试转换为 ObservableList 时也遇到错误:
incompatible types: inference variable E has incompatible bounds
equality constraints: Workout
lower bounds: WorkoutTableModel
where E is a type-variable:
E extends Object declared in method <E>observableArrayList(E...)
The type of <E>observableArrayList(E...) is erroneous
where E is a type-variable:
E extends Object declared in method <E>observableArrayList(E...)
谢谢!
table 型号:
package myworkouts.presentation;
import myworkouts.domain.*;
import java.util.*;
import javax.swing.table.AbstractTableModel;
public class WorkoutTableModel extends AbstractTableModel {
private String[] columnNames = {"Date", "Route", "Distance", "Time"};
private List<Workout> workouts = new LinkedList<Workout>();
public void setWorkouts(List<Workout> workouts) {
this.workouts = workouts;
}
@Override
public int getRowCount() {
return workouts.size();
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int row, int column) {
Workout workout = workouts.get(row);
switch (column) {
case 0:
return workout.getDate();
case 1:
return workout.getRoute();
case 2:
return workout.getDistance();
case 3:
return workout.getTime();
}
return "";
}
@Override
public String getColumnName(int column) {
return columnNames[column];
}
}
mainUI 片段:
public class MainUI extends Application {
private Account account = null;
private WorkoutTableModel model = new WorkoutTableModel();
final ObservableList<Workout> data = FXCollections.observableArrayList(model);
public void setAccount(Account account) {
this.account = account;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Workout CRUD form JavaFX Application");
TableView workoutsTbl = new TableView();
workoutsTbl.setEditable(true);
workoutsTbl.setItems(model);
// Add workoutsTbl header
Text headerLabel = new Text("Workouts");
headerLabel.getStyleClass().add("header");
// add workoutsTbl column labels
TableColumn dateCol = new TableColumn("Date");
TableColumn routeCol = new TableColumn("Route");
TableColumn distanceCol = new TableColumn("Distance");
TableColumn timeCol = new TableColumn("Time");
workoutsTbl.getColumns().addAll(dateCol, routeCol, distanceCol, timeCol);
workoutsTbl.autosize();
VBox vbox = new VBox(10);
vbox.setSpacing(5);
vbox.setPadding(new Insets(10,5,5,10));
// Create the registration form grid pane
GridPane gridPane = createWorkoutsFormPane();
//gridPane.add(workoutsTbl,1,10,2,5);
vbox.getChildren().addAll(headerLabel,workoutsTbl,gridPane);
// Add UI controls to the registration form grid pane
addUIControls(gridPane);
// Create a scene with registration form grid pane as the root node
Scene scene = new Scene(vbox, 520, 500);
// Set the scene in primary stage
primaryStage.setScene(scene);
scene.getStylesheets().add
(MainUI.class.getResource("Login.css").toExternalForm());
primaryStage.show();
}
最终 ObservableList 数据 = FXCollections.observableArrayList(模型);
Swing AbstractTableModel 不是 List-type 东西。看看它的声明,看看它实现了什么。这不是李斯特。