FXMLのtablecolumnにデータを追加したいと思い、調べて見たところ、
(columnのfx:id).setCellValueFactory(new PropertyValueFactory<(追加したいリストの型), String>(""));
の形でcontrollerクラスと追加したいデータのクラスを関連付けることでデータを追加できると理解したのですが、実際に試したところ、引数の型が違うと警告が出てしまいました。
ほかに調べてみても、自分の力ではこれ以上の情報が出てこないので、力を貸していただきたいです。
controller
1/** 2 * Sample Skeleton for 'ScheduleIndividual.fxml' Controller Class 3 */ 4 5package application; 6 7import java.net.URL; 8import java.util.ResourceBundle; 9 10import javafx.fxml.FXML; 11import javafx.scene.control.TableColumn; 12import javafx.scene.control.TableView; 13import javafx.scene.control.cell.PropertyValueFactory; 14 15public class SceduleTableController { 16 17 @FXML // ResourceBundle that was given to the FXMLLoader 18 private ResourceBundle resources; 19 20 @FXML // URL location of the FXML file that was given to the FXMLLoader 21 private URL location; 22 23 @FXML // fx:id="column" 24 private TableColumn<?, ?> column; // Value injected by FXMLLoader 25 26 @FXML // fx:id="tableView1" 27 private TableView<?> tableView1; // Value injected by FXMLLoader 28 29 @FXML // This method is called by the FXMLLoader when initialization is complete 30 void initialize() { 31 32 column.setCellValueFactory(new PropertyValueFactory<ScheduleData, String>("tgtDate")); 33 assert column != null : "fx:id=\"column\" was not injected: check your FXML file 'ScheduleIndividual.fxml'."; 34 assert tableView1 != null : "fx:id=\"tableView1\" was not injected: check your FXML file 'ScheduleIndividual.fxml'."; 35 36 } 37 38 39}
data
1package application; 2 3import javafx.beans.property.SimpleStringProperty; 4import javafx.beans.property.StringProperty; 5 6public class ScheduleData { 7 private StringProperty data; 8 9 public StringProperty dataProperty() { 10 return data; 11 } 12 13 public ScheduleData(String data) { 14 this.data = new SimpleStringProperty(data); 15 } 16} 17
下のコードはコンソールです。
console
1javafx.fxml.LoadException: 2/C:/Users/user/workspace/SceduleTable/bin/application/ScheduleIndividual.fxml 3 4 at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625) 5 at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2595) 6 at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466) 7 at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237) 8 at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194) 9 at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163) 10 at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136) 11 at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113) 12 at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106) 13 at fxproject/application.SceduleMain.start(SceduleMain.java:14) 14 at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846) 15 at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455) 16 at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428) 17 at java.base/java.security.AccessController.doPrivileged(Native Method) 18 at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427) 19 at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96) 20 at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 21 at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174) 22 at java.base/java.lang.Thread.run(Thread.java:834) 23Caused by: java.lang.reflect.InvocationTargetException 24 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 25 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 26 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 27 at java.base/java.lang.reflect.Method.invoke(Method.java:566) 28 at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76) 29 at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) 30 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 31 at java.base/java.lang.reflect.Method.invoke(Method.java:566) 32 at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273) 33 at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83) 34 at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2591) 35 ... 17 more 36Caused by: java.lang.Error: Unresolved compilation problem: 37 型 TableColumn<capture#1-of ?,capture#2-of ?> のメソッド setCellValueFactory(Callback<TableColumn.CellDataFeatures<capture#1-of ?,capture#2-of ?>,ObservableValue<capture#2-of ?>>) は引数 (PropertyValueFactory<ScheduleData,String>) に適用できません 38 39 at fxproject/application.SceduleTableController.initialize(SceduleTableController.java:32) 40 ... 28 more 41
バージョン
・jdk11
・e(fx)clipse 3.7.0
よろしくお願いします<m(__)m>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。