标签: listproperty

在JavaFX中使用ListProperty

我定义了一个包含列表的类.我试图用传输列表初始化构造函数中的列表:

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; }
}
Run Code Online (Sandbox Code Playgroud)

该类Priority包含两个字段及其getter:

public IntegerProperty rate;  
public StringProperty speciality;
Run Code Online (Sandbox Code Playgroud)

可能是我没有ListProperty正确使用?

当我尝试创建对象时:

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start …
Run Code Online (Sandbox Code Playgroud)

list listproperty javafx-2

6
推荐指数
1
解决办法
1万
查看次数

SimpleListProperty上的NotSerializableException

我正在使用Javafx,并将我的对象包装到ListProperty中,以使tableview更新列表对象的任何更改.现在我正在尝试序列化我的项目和ListProperty对象,它给我带来了这个异常.

java.io.NotSerializableException: javafx.beans.property.SimpleListProperty
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1181)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1541)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1506)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1429)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1175)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at Util.FileManager.serializeProject(FileManager.java:23)
at Controller.FrameworkController.saveProject(FrameworkController.java:549)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1435)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.control.MenuItem.fire(MenuItem.java:456)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1197)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer$6.handle(ContextMenuContent.java:1148)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer$6.handle(ContextMenuContent.java:1146)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at …
Run Code Online (Sandbox Code Playgroud)

javafx listproperty notserializableexception

5
推荐指数
2
解决办法
6735
查看次数

是否可以在App Engine模型中动态命名属性?

setattr允许您在Py​​thon类中动态命名属性.我正在尝试使用App Engine模型做类似的事情:

class MyModel(db.Model):
    def __init__(self, *args, **kwargs):
        super(MyModel, self).__init__(*args, **kwargs)

        # Doesn't fully work
        setatr(self, 'prop1', db.ListProperty(db.Key))
        setatr(self, 'prop2', db.StringListProperty())

    # Works fully
    # prop1 = db.ListProperty(db.Key))
    # prop2 = db.StringListProperty())
Run Code Online (Sandbox Code Playgroud)

这段代码编译,但是当我model.prop1.append(key)稍后调用时,我收到此错误:

AttributeError: 'ListProperty' object has no attribute 'append'
Run Code Online (Sandbox Code Playgroud)

我怀疑这是因为prop1在模型中声明而不是self.prop1,但我不完全理解语法的意义.

有没有人完成这个,或者有没有人对语法差异有任何见解?

google-app-engine dynamic setattribute setattr listproperty

1
推荐指数
1
解决办法
488
查看次数

JavaFX中是否有可更改的ListProperty?

ListPropertyJavaFX中是否有可更改?我需要一个ListProperty支持add()remove()方法,但我找不到一个. SimpleListProperty会扔UnsupportedOperationException.

我发现只是使用初始化程序来设置内容,但这不是我需要的.我需要从那里开始一个空的Property end buld.

我不敢相信没有这样的事情; 不知怎的,我一定是个盲人.有人能指出我正确的方向吗?

java javafx add listproperty

1
推荐指数
1
解决办法
473
查看次数