【发布时间】:2025-12-13 13:15:01
【问题描述】:
我有 ObservableList 类 GameLogEntry 的实例:
public class GameLogEntry {
private int gameNumber;
private int chosenStratA;
private int chosenStratB;
private Double[] scoresByB;
private Double[] scoresByA;
private double higherPrice;
private double lowerPrice;
private double averagePrice;
private int maxIndex;
在我的程序中,我使用来自这个 ObservableList 的值填充 TableView 的列。
我的专栏:
@FXML
private TableColumn<GameLogEntry, String> colGameNum;
@FXML
private TableColumn<GameLogEntry, String> colChosenStratA;
@FXML
private TableColumn<GameLogEntry, String> colScoreByBOne;
@FXML
private TableColumn<GameLogEntry, String> colScoreByBTwo;
@FXML
private TableColumn<GameLogEntry, String> colChosenStratB;
@FXML
private TableColumn<GameLogEntry, String> colScoreByAOne;
@FXML
private TableColumn<GameLogEntry, String> colScoreByATwo;
@FXML
private TableColumn<GameLogEntry, String> colLowerPrice;
@FXML
private TableColumn<GameLogEntry, String> colHigherPrice;
@FXML
private TableColumn<GameLogEntry, String> colAveragePrice;
我在initialize 方法中这样做:
colGameNum.setCellValueFactory(new PropertyValueFactory<GameLogEntry, String>("gameNumber"));
colChosenStratA.setCellValueFactory(new PropertyValueFactory<GameLogEntry, String>("chosenStratA"));
colChosenStratB.setCellValueFactory(new PropertyValueFactory<GameLogEntry, String>("chosenStratB"));
colHigherPrice.setCellValueFactory(new PropertyValueFactory<GameLogEntry, String>("higherPrice"));
colLowerPrice.setCellValueFactory(new PropertyValueFactory<GameLogEntry, String>("lowerPrice"));
colAveragePrice.setCellValueFactory(new PropertyValueFactory<GameLogEntry, String>("averagePrice"));
但我还需要填写 CS(B1)、CS(B2)、CS(A1) 和 CS(A2) 列。
CS(B1) 应该用 scoreByB[0] 填充,
CS(B2) - 使用 scoreByB[1],
CS(A1) - 使用 scoreByA[0],
CS(A2) - 使用 scoreByA[1]。
问题是 - 我可以使用与其他值相同的简单方法吗?如果没有,我该如何以其他方式做到这一点?
【问题讨论】:
-
@Sedrick 我真的不明白这个问题与我的问题有什么关系。如果您认为这是同一个问题,请您根据我的问题向我解释一下吗?
-
你是对的。抱歉答错了。
-
*.com/questions/20769723/… 这更接近你的要求