javaswingswing-app-framework

Resource files with Swing Application Framework


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...


Solution

  • 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.