teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

試したことの追加(調べたこと、バージョンなどを記載せず、投げやりな質問でした。すみません)

2021/04/05 11:43

投稿

ryu-bamboo
ryu-bamboo

スコア9

title CHANGED
File without changes
body CHANGED
@@ -1,1 +1,120 @@
1
- FXMLのtablecolumnにデータを追加する方法と、行を追加する方法を教え頂きいです
1
+ FXMLのtablecolumnにデータを追加したい思い調べところ、
2
+
3
+ (columnのfx:id).setCellValueFactory(new PropertyValueFactory<(追加したいリストの型), String>(""));
4
+
5
+  の形でcontrollerクラスと追加したいデータのクラスを関連付けることでデータを追加できると理解したのですが、実際に試したところ、引数の型が違うと警告が出てしまいました。
6
+  ほかに調べてみても、自分の力ではこれ以上の情報が出てこないので、力を貸していただきたいです。
7
+
8
+ ```controller
9
+ /**
10
+ * Sample Skeleton for 'ScheduleIndividual.fxml' Controller Class
11
+ */
12
+
13
+ package application;
14
+
15
+ import java.net.URL;
16
+ import java.util.ResourceBundle;
17
+
18
+ import javafx.fxml.FXML;
19
+ import javafx.scene.control.TableColumn;
20
+ import javafx.scene.control.TableView;
21
+ import javafx.scene.control.cell.PropertyValueFactory;
22
+
23
+ public class SceduleTableController {
24
+
25
+ @FXML // ResourceBundle that was given to the FXMLLoader
26
+ private ResourceBundle resources;
27
+
28
+ @FXML // URL location of the FXML file that was given to the FXMLLoader
29
+ private URL location;
30
+
31
+ @FXML // fx:id="column"
32
+ private TableColumn<?, ?> column; // Value injected by FXMLLoader
33
+
34
+ @FXML // fx:id="tableView1"
35
+ private TableView<?> tableView1; // Value injected by FXMLLoader
36
+
37
+ @FXML // This method is called by the FXMLLoader when initialization is complete
38
+ void initialize() {
39
+
40
+ column.setCellValueFactory(new PropertyValueFactory<ScheduleData, String>("tgtDate"));
41
+ assert column != null : "fx:id=\"column\" was not injected: check your FXML file 'ScheduleIndividual.fxml'.";
42
+ assert tableView1 != null : "fx:id=\"tableView1\" was not injected: check your FXML file 'ScheduleIndividual.fxml'.";
43
+
44
+ }
45
+
46
+
47
+ }
48
+ ```
49
+
50
+ ```data
51
+ package application;
52
+
53
+ import javafx.beans.property.SimpleStringProperty;
54
+ import javafx.beans.property.StringProperty;
55
+
56
+ public class ScheduleData {
57
+ private StringProperty data;
58
+
59
+ public StringProperty dataProperty() {
60
+ return data;
61
+ }
62
+
63
+ public ScheduleData(String data) {
64
+ this.data = new SimpleStringProperty(data);
65
+ }
66
+ }
67
+
68
+ ```
69
+
70
+ 下のコードはコンソールです。
71
+
72
+ ```console
73
+ javafx.fxml.LoadException:
74
+ /C:/Users/user/workspace/SceduleTable/bin/application/ScheduleIndividual.fxml
75
+
76
+ at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
77
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2595)
78
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
79
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
80
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
81
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
82
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
83
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
84
+ at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
85
+ at fxproject/application.SceduleMain.start(SceduleMain.java:14)
86
+ at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
87
+ at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
88
+ at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
89
+ at java.base/java.security.AccessController.doPrivileged(Native Method)
90
+ at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
91
+ at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
92
+ at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
93
+ at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
94
+ at java.base/java.lang.Thread.run(Thread.java:834)
95
+ Caused by: java.lang.reflect.InvocationTargetException
96
+ at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
97
+ at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
98
+ at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
99
+ at java.base/java.lang.reflect.Method.invoke(Method.java:566)
100
+ at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
101
+ at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
102
+ at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
103
+ at java.base/java.lang.reflect.Method.invoke(Method.java:566)
104
+ at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273)
105
+ at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
106
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2591)
107
+ ... 17 more
108
+ Caused by: java.lang.Error: Unresolved compilation problem:
109
+ 型 TableColumn<capture#1-of ?,capture#2-of ?> のメソッド setCellValueFactory(Callback<TableColumn.CellDataFeatures<capture#1-of ?,capture#2-of ?>,ObservableValue<capture#2-of ?>>) は引数 (PropertyValueFactory<ScheduleData,String>) に適用できません
110
+
111
+ at fxproject/application.SceduleTableController.initialize(SceduleTableController.java:32)
112
+ ... 28 more
113
+
114
+ ```
115
+
116
+ バージョン
117
+ ・jdk11
118
+ ・e(fx)clipse 3.7.0
119
+
120
+ よろしくお願いします<m(__)m>