Spring Swing Integration
Spring does not play nicely with beans that are created outside of its application context.
What's the best way in letting me design my forms using JFormDesigner but then using Spring to manage the actions of the components?
There are a few开发者_运维知识库 ways of integrating Spring and Swing (eg https://www.ibm.com/developerworks/java/tutorials/j-springswing/) but this approach involves you having to extend every control that you wish to use, an approach that looks like it would add a quite a lot of uneccesary overhead. Also this approach does not allow me to use JFormDesigner to model the look of my form.
I've also had a look at the Spring Rich Client Project but that doesn't look like it's migrated to Spring 3 yet, although that's looking likely to restart development soon as they have moved the project hosting to Github.
I have an app which uses Swing, JFormDesigner built panels, Spring and Spring RCP. There is a view class, which extends RCP's AbstractView
, for each view, which has references to both the panel (as we call it) and the actions, so it can manage them. Each view has one main panel (that can be built with JFormDesigner), which is the one that the view has a reference to. I don't know if this is the best way, but it works quite well.
The main problem that I am having is that defining simple listeners that have reference to the panel requires too much configuration if you want to make them Spring beans. And if you don't, you have to pass the reference to all needed Spring resources (panel, service interface, etc) manually, which is also a lot of work. I have partially solved this by writing a static getter for the most common Spring beans to a class that has an access to the application context.
What is the problem of configuring Spring to manage both the actions and the forms? In our app the panel has been simply defined as a property of the view in the application config, nothing special about it.
精彩评论