java - 如何通过Spring setter注入(inject)设置JFrame的大小?

标签 java spring swing

我正在尝试使用 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/

相关文章:

java - 在另一个方法中使用时,无法解析 JComponent 名称

java - 我的 ListView 不起作用。我在这里错过了一些东西

java - 松耦合和紧耦合将用作真实场景的地方?

java - 在生产环境中加载 index.jsp 时出错,但在开发环境中不会

java - Spring Neo4j 保存 MultipartFile

java - 支持 Javascript 和 CSS 的 JEditorPane

java - JList 复制选择

java - 如何在 Eclipse 中使用 Ant 源?

spring - 为什么我们需要在 spring-boot-starter-jersey 项目中为 Jersey 资源提供 @Component spring 注解?

java - Spring REST API 并防止更改自动生成的属性?