Swing 应用程序框架的资源文件

发布于 2024-08-20 20:45:58 字数 1130 浏览 5 评论 0原文

有人可以解释当我的应用程序中有多个包时应该如何使用资源注入吗?除了具有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不美如何 2024-08-27 20:45:58

有趣的是,向别人提问有助于解决问题。

执行此操作的方法是将属性文件放入 view/resources 并打开资源映射,如下所示:

    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);

我不知道为什么这之前不起作用,也许我以某种方式弄乱了资源文件。

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:

    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);

I have no idea why this didn't work before, maybe I had messed up the resource files somehow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文