开发者

Resource files with Swing Application Framework

开发者 https://www.devze.com 2022-12-19 18:44 出处:网络
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 SingleFrameA

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 co开发者_运维问答uld 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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号