gpt4 book ai didi

JavaFX-TableView-setItems : The method setItems(ObservableList) in the type TableView is not applicable for the arguments (ObservableList)

转载 作者:行者123 更新时间:2023-11-30 02:26:46 35 4
gpt4 key购买 nike

当我尝试将项目设置到 tableView 中时遇到问题,有关我使用 SceneBuilder 的信息。

Main.java:

public class Main extends Application {
private static Stage theStage;
public static void main(String[] args) throws Exception {
testDatas();
launch();
}

public void start(Stage stage) throws IOException {
theStage = stage;
Group acteur = new Group();
acteur.getChildren().add(
FXMLLoader.load(getClass().getResource("views/options.fxml")));
theStage.setTitle("Where's My Money");
Scene scene = new Scene(acteur, 1280.0, 720.0);
theStage.setScene(scene);
theStage.show();
}

public static void initialize() {
launch();
}

public static void setScene(Group acteur, String titre) throws IOException {
Scene scene = new Scene(acteur);

theStage.setTitle(titre);
theStage.setScene(scene);
theStage.show();
}
}

View /ControllerOptions.class

public class ControllerOptions implements Initializable{

@FXML private TableView<?> TV_currency;
@FXML private TableColumn<Currency, String> TC_name;
@FXML private TableColumn<Currency, Double> TC_value;
private ObservableList<Currency> currencies = FXCollections.observableArrayList();

//FUNCTIONS
@Override
public void initialize(URL location, ResourceBundle rb){
//initialisation Table Currencies
for (Currency currency : Datas.getInstance().getCurrencies()) {
currencies.add(currency);
}
TC_name.setCellValueFactory(new PropertyValueFactory<Currency, String>("name"));
TC_value.setCellValueFactory(new PropertyValueFactory<Currency, Double>("value"));
TV_currency.setItems(currencies); // <= HERE'S THE ERROR
}
}

模型/Currency.class

public class Currency {

private String name;
private double value;

public Currency(String name, double value) {
setName(name);
setValue(value);
}

public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}

public void setValue(double value) {
this.value = value;
}
public double getValue() {
return value;
}
}

我有这个错误:TableView 类型中的方法 setItems(ObservableList) 不适用于参数 (ObservableList)

如果您能帮助我,我将非常感激。

提前致谢

最佳答案

您将支持数据正确声明为

private ObservableList<Currency> currencies ;

但是您使用通配符声明了该表:

@FXML private TableView<?> TV_currency;

因此,当您尝试设置表中的项目时,类型不匹配。

将表的声明更改为

@FXML private TableView<Currency> TV_currency;

关于JavaFX-TableView-setItems : The method setItems(ObservableList) in the type TableView is not applicable for the arguments (ObservableList),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45465944/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com