Swing 应用程序框架的资源文件
有人可以解释当我的应用程序中有多个包时应该如何使用资源注入吗?除了具有 SingleFrameApplication 后代的包之外,我似乎无法加载任何其他包中的资源。假设我的应用程序结构如下:
/resources
/main
/main/resources
/view
/view/resources
这是正确的吗?我尝试阅读我能找到的小文档,但我无法弄清楚是否应该将 /view/mainView.class 的资源文件放入 /resources、/main/resources 或 /view/resources。
以及如何打开资源文件?我尝试将资源文件放入 /main/resources 并打开 mainTableView 的资源文件,因为
this.resourceMap = org.jdesktop.application.Application.getInstance(scheator.ScheatorApp.class).getContext().getResourceMap(MainTablePanel.class);
this.actionMap = org.jdesktop.application.Application.getInstance(scheator.ScheatorApp.class).getContext().getActionMap(MainTablePanel.class, this);
ScheatorApp 是主类(SingleFrameApplication 后代)。属性文件有类似的行,
ColRound.text = Round
ColHome.text = Home
ColAway.text = Away
但是当我尝试这样做时:
columnNames[0] = resourceMap.getString("ColRound.text");
columnNames[1] = resourceMap.getString("ColHome.text");
columnNames[2] = resourceMap.getString("ColAway.text");
所有列名称都是空的。
而且我什至还没有尝试过资源注入......
Could someone explain how I should use resource injection when I have several packages in my application? I seem unable to load resources in any other package but the one where I have the SingleFrameApplication descendant. Let's say this is what my application structure looks like:
/resources
/main
/main/resources
/view
/view/resources
Is this correct? I have tried to read the little documentation I could find but I'm unable to figure out if I should put the resource file for /view/mainView.class to /resources, /main/resources or /view/resources.
And how do I open the resource file? I have tried putting the resource file to /main/resources and opening the resource file for mainTableView as
this.resourceMap = org.jdesktop.application.Application.getInstance(scheator.ScheatorApp.class).getContext().getResourceMap(MainTablePanel.class);
this.actionMap = org.jdesktop.application.Application.getInstance(scheator.ScheatorApp.class).getContext().getActionMap(MainTablePanel.class, this);
ScheatorApp is the main class (SingleFrameApplication descendant). The properties file has lines like
ColRound.text = Round
ColHome.text = Home
ColAway.text = Away
But when I try this:
columnNames[0] = resourceMap.getString("ColRound.text");
columnNames[1] = resourceMap.getString("ColHome.text");
columnNames[2] = resourceMap.getString("ColAway.text");
All the column names are empty.
And I haven't even tried resource injection yet...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有趣的是,向别人提问有助于解决问题。
执行此操作的方法是将属性文件放入 view/resources 并打开资源映射,如下所示:
我不知道为什么这之前不起作用,也许我以某种方式弄乱了资源文件。
Funny how asking from others helps solve problems.
The way to do this is to put the properties file to view/resources and opening the resource map like this:
I have no idea why this didn't work before, maybe I had messed up the resource files somehow.