質問編集履歴

1

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

2021/04/05 11:43

投稿

ryu-bamboo
ryu-bamboo

スコア9

test CHANGED
File without changes
test CHANGED
@@ -1 +1,239 @@
1
- FXMLのtablecolumnにデータを追加する方法と、行を追加する方法を教え頂きいです
1
+ FXMLのtablecolumnにデータを追加したい思い調べところ、
2
+
3
+
4
+
5
+ (columnのfx:id).setCellValueFactory(new PropertyValueFactory<(追加したいリストの型), String>(""));
6
+
7
+
8
+
9
+  の形でcontrollerクラスと追加したいデータのクラスを関連付けることでデータを追加できると理解したのですが、実際に試したところ、引数の型が違うと警告が出てしまいました。
10
+
11
+  ほかに調べてみても、自分の力ではこれ以上の情報が出てこないので、力を貸していただきたいです。
12
+
13
+
14
+
15
+ ```controller
16
+
17
+ /**
18
+
19
+ * Sample Skeleton for 'ScheduleIndividual.fxml' Controller Class
20
+
21
+ */
22
+
23
+
24
+
25
+ package application;
26
+
27
+
28
+
29
+ import java.net.URL;
30
+
31
+ import java.util.ResourceBundle;
32
+
33
+
34
+
35
+ import javafx.fxml.FXML;
36
+
37
+ import javafx.scene.control.TableColumn;
38
+
39
+ import javafx.scene.control.TableView;
40
+
41
+ import javafx.scene.control.cell.PropertyValueFactory;
42
+
43
+
44
+
45
+ public class SceduleTableController {
46
+
47
+
48
+
49
+ @FXML // ResourceBundle that was given to the FXMLLoader
50
+
51
+ private ResourceBundle resources;
52
+
53
+
54
+
55
+ @FXML // URL location of the FXML file that was given to the FXMLLoader
56
+
57
+ private URL location;
58
+
59
+
60
+
61
+ @FXML // fx:id="column"
62
+
63
+ private TableColumn<?, ?> column; // Value injected by FXMLLoader
64
+
65
+
66
+
67
+ @FXML // fx:id="tableView1"
68
+
69
+ private TableView<?> tableView1; // Value injected by FXMLLoader
70
+
71
+
72
+
73
+ @FXML // This method is called by the FXMLLoader when initialization is complete
74
+
75
+ void initialize() {
76
+
77
+
78
+
79
+ column.setCellValueFactory(new PropertyValueFactory<ScheduleData, String>("tgtDate"));
80
+
81
+ assert column != null : "fx:id=\"column\" was not injected: check your FXML file 'ScheduleIndividual.fxml'.";
82
+
83
+ assert tableView1 != null : "fx:id=\"tableView1\" was not injected: check your FXML file 'ScheduleIndividual.fxml'.";
84
+
85
+
86
+
87
+ }
88
+
89
+
90
+
91
+
92
+
93
+ }
94
+
95
+ ```
96
+
97
+
98
+
99
+ ```data
100
+
101
+ package application;
102
+
103
+
104
+
105
+ import javafx.beans.property.SimpleStringProperty;
106
+
107
+ import javafx.beans.property.StringProperty;
108
+
109
+
110
+
111
+ public class ScheduleData {
112
+
113
+ private StringProperty data;
114
+
115
+
116
+
117
+ public StringProperty dataProperty() {
118
+
119
+ return data;
120
+
121
+ }
122
+
123
+
124
+
125
+ public ScheduleData(String data) {
126
+
127
+ this.data = new SimpleStringProperty(data);
128
+
129
+ }
130
+
131
+ }
132
+
133
+
134
+
135
+ ```
136
+
137
+
138
+
139
+ 下のコードはコンソールです。
140
+
141
+
142
+
143
+ ```console
144
+
145
+ javafx.fxml.LoadException:
146
+
147
+ /C:/Users/user/workspace/SceduleTable/bin/application/ScheduleIndividual.fxml
148
+
149
+
150
+
151
+ at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
152
+
153
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2595)
154
+
155
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
156
+
157
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
158
+
159
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
160
+
161
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
162
+
163
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
164
+
165
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
166
+
167
+ at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
168
+
169
+ at fxproject/application.SceduleMain.start(SceduleMain.java:14)
170
+
171
+ at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
172
+
173
+ at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
174
+
175
+ at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
176
+
177
+ at java.base/java.security.AccessController.doPrivileged(Native Method)
178
+
179
+ at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
180
+
181
+ at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
182
+
183
+ at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
184
+
185
+ at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
186
+
187
+ at java.base/java.lang.Thread.run(Thread.java:834)
188
+
189
+ Caused by: java.lang.reflect.InvocationTargetException
190
+
191
+ at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
192
+
193
+ at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
194
+
195
+ at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
196
+
197
+ at java.base/java.lang.reflect.Method.invoke(Method.java:566)
198
+
199
+ at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
200
+
201
+ at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
202
+
203
+ at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
204
+
205
+ at java.base/java.lang.reflect.Method.invoke(Method.java:566)
206
+
207
+ at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273)
208
+
209
+ at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
210
+
211
+ at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2591)
212
+
213
+ ... 17 more
214
+
215
+ Caused by: java.lang.Error: Unresolved compilation problem:
216
+
217
+ 型 TableColumn<capture#1-of ?,capture#2-of ?> のメソッド setCellValueFactory(Callback<TableColumn.CellDataFeatures<capture#1-of ?,capture#2-of ?>,ObservableValue<capture#2-of ?>>) は引数 (PropertyValueFactory<ScheduleData,String>) に適用できません
218
+
219
+
220
+
221
+ at fxproject/application.SceduleTableController.initialize(SceduleTableController.java:32)
222
+
223
+ ... 28 more
224
+
225
+
226
+
227
+ ```
228
+
229
+
230
+
231
+ バージョン
232
+
233
+ ・jdk11
234
+
235
+ ・e(fx)clipse 3.7.0
236
+
237
+
238
+
239
+ よろしくお願いします<m(__)m>