当我试图将项目设置到tableView中时,我遇到了一个问题,因为我使用SceneBuilder获取信息。
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();
}
}
视图/控制器选项.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
}
}
型号/货币.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(ObservalElist)不适用于参数(ObservalElist)
如果你能帮助我,我将非常感激。
提前感谢