Problem with component resource injection using Swing Application Framework

I am having a problem using the Swing Application Framework Resource Injection Component, I read the tutorial provided by Sun, and it works.

The fact is that I have a Program class that extends from the SingleFrameApplication provided by SAF, now I want to get the text of my components (buttons and labels, etc.) from the properties file and works as expected for this Program class (I created subdirectory called resources and put the Program.properties file there). But I have a MainFrame inside a mainpkg.gui named mainpkg.gui (the Program is in the mainpkg package), and I created the corresponding resources subsubpackage to host the MainFrame.properties file, and it does not work! I can’t get the package (automatically, I think if I use the ResourceMap.getXXX() method, I would get the material.

What am I doing wrong?

Thanks in advance!

+4
source share
1 answer

I know this is an old question, but here I think the problem is:

First, if you use SingleFrameApplication , you should not create your own JFrame . Instead, you should have a startup() method like this:

 @Override protected void startup() { final FrameView view = getMainView(); view.setMenuBar(createMenuBar()); view.setComponent(createMainComponent()); show(view); } 

Now the show(view) method takes care of putting all these resources into components. But it only handles components that are in the view component hierarchy at the moment you call show() . If you add something later, you will have to enter the resources yourself. Here is an example of how you could do this:

 public void injectResources(final Component root) { final ResourceMap resourceMap = applicationContext.getResourceMap(root .getClass(), Object.class); resourceMap.injectComponents(root); resourceMap.injectFields(root); } 

I hope this helps you or someone else with the same problem.

+1
source

Source: https://habr.com/ru/post/1310424/


All Articles