我正在尝试使用 Spring 初始化 JFrame。 Frame 出现了,直到我设置了 size 属性(MainFrame 只是扩展了 JFrame)。
<bean id="mainFrame" class="package.MainFrame" init-method="init" >
<property name="title" value="Setting the title works ..." />
<property name="size">
<bean class="java.awt.Dimension" >
<constructor-arg value="600" />
<constructor-arg value="800" />
</bean>
</property>
</bean>
我收到的错误消息是:
NotWritablePropertyException: Invalid property 'size' of bean class [package.MainFrame]: Bean property 'size' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
JFrame 类有一个 setter setSize(Dimension) 和一个 getter getSize(Dimension)。我做错了什么?
最佳答案
JFrame.setSize
有两个重载版本:setSize(int, int)
和 setSize(java.awt.Dimension)
。所以 spring 猜测 size 不是 bean 属性。
关于java - 如何通过Spring setter注入(inject)设置JFrame的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26362069/