在JavaFX中使用ListProperty
发布时间:2020-05-25 17:16:35 所属栏目:Java 来源:互联网
导读:我定义了一个包含列表的类.我试图用传输列表初始化构造函数中的列表: public class Person { public IntegerProperty id; public ListPropertyPriority choice; public Person(int id, ListPriority list) { this.id = new
|
我定义了一个包含列表的类.我试图用传输列表初始化构造函数中的列表: public class Person {
public IntegerProperty id;
public ListProperty<Priority> choice;
public Person(int id,List<Priority> list) {
this.id = new SimpleIntegerProperty(id);
this.choice = new SimpleListProperty<Priority>();
for (int i = 0; i < 5; i++) {
this.choice.add(list.get(i));
}
}
public IntegerProperty idProperty() { return id; }
public ListProperty<Priority> choiceProperty() { return choice; }
}
类优先级包含两个字段及其getter: public IntegerProperty rate; public StringProperty speciality; 难道我没有正确使用ListProperty吗? 当我尝试创建对象时: Exception in Application start method Exception in thread "main" java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403) at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47) at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115) at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.UnsupportedOperationException at java.util.AbstractList.add(AbstractList.java:148) at java.util.AbstractList.add(AbstractList.java:108) at java.util.AbstractCollection.addAll(AbstractCollection.java:334) at javafx.beans.binding.ListExpression.addAll(ListExpression.java:280) at Person.setAllchoice(Person.java:24) at Person.<init>(Person.java:17) at Distribution.ReadDataFromFile(Distribution.java:85) at Distribution.start(Distribution.java:28) at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215) at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179) at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76) at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:82) ... 1 more 解决方法尝试以这种方式初始化SimpleListProperty:public Person(int id,List<Priority> list) {
...
ObservableList<Priority> observableList = FXCollections.observableArrayList(list)
this.choice = new SimpleListProperty<Priority>(observableList);
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 基于JavaBean编辑器读取peroperties文件的实例
- 为什么Java 6编译的类大小大于Java 5?
- Java压缩文件工具类ZipUtil使用方法代码示例
- Java中的Boxing和AutoBoxing有什么区别?
- java – Eclipse生成的equals是否有任何特殊原因使用1231和
- java – 了解Hibernate的hibernate.max_fetch_depth和hiber
- 利用java制作简单的音乐播放器
- java – 在Spark中,是否可以在两个执行程序之间共享数据?
- Spring boot注解@Async线程池实例详解
- java – Mockito失败,内联的模拟启用了无效的参数名称异常
