如何通过Spring setter注入来设置JFrame的大小



我正在尝试使用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(Dimition)。我做错了什么?

JFrame.setSize有两个重载版本:setSize(int, int)setSize(java.awt.Dimension)。所以spring猜测大小不是bean的属性。

<bean id="frame" class="javax.swing.JFrame">
        <property name="title" value="First swing-spring project"/>
                <property name="size"> 
            <bean class="java.awt.Dimension">
                <constructor-arg value="300"/>
                <constructor-arg value="400"/>
            </bean>
        </property>
        <property name="defaultCloseOperation" value="3"/>
        <property name="visible" value="true"/>
    </bean>

最新更新