Skip to main content

Swing Application framework: WARNING: No saved state for org.jdesktop.swingx.JXTable

5 replies [Last post]
szd116
Offline
Joined: 2012-01-05

Hello,
I am trying the example listed in this page:
http://carsten-oland.blogspot.com/2009/08/persisting-jxtables-column-con...
but I have been getting warnings like No saved state for org.jdesktop.swingx.JXTable
and yes, i have setName and overridden the dispose method. the following is my main function and the rest of the code are exactly the same from the tutorial listed above, please help. Thank you.

import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

import org.jdesktop.swingx.JXTable;

public class TestJXTable extends JFrame {

String data[][] = { { "John", "Sutherland", "Student" },
{ "George", "Davies", "Student" },
{ "Melissa", "Anderson", "Associate" },
{ "Stergios", "Maglaras", "Developer" }, };

String fields[] = { "Name", "Surname", "Status" };

ModuleApplicationContext mac;

JXTable jt;

JScrollPane pane;

public void dispose()
{
jt.getParent().remove(jt);
try {
mac.getSessionStorage().save(jt, "testTable.xml");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.dispose();
// System.exit(0);
}

public static void main(String[] argv) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
TestJXTable myExample = new TestJXTable(
"JXTable Example");
}
});
}

public TestJXTable(String title) {
super(title);
// save settings in users home dir
mac = new ModuleApplicationContext(System.getProperty("user.home"));
setSize(150, 150);
init();
pack();
setVisible(true);
}

private void init() {
jt = new JXTable(data, fields);
jt.setColumnControlVisible(true);
jt.setName("testTable");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
pane = new JScrollPane(jt);
pane.setName("testPane");
try {
mac.getSessionStorage().restore(jt, "testTable.xml");
} catch (IOException e) {
e.printStackTrace();
}
getContentPane().add(pane);
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
martinm1000
Offline
Joined: 2003-06-12

Well... no good news...

I've tried to copy code from kleopatra into simple JSR-296 (AppFramework) project and that didn't work. I recently updated to BSAF. Now, looking at their code, I think you need to have the java webstart jar in your path to test the session/storage code right inside Netbeans.

My code is a simple Frame -> JPanel -> JScrollPane -> JXTable.

I've decided to bypass Kleopatra's code, and just try the base implementation from BSAF (column sizes of JTables). Well that code is **** and seems totally broken (sorry). First thing, you will need to have name on everything (if not, an NPE will kill your app, which is well pretty sad. I dont care if that code can fail, but don't kill my app for that!).

But anyway, here is the component path that BSAF saved :

"table/JViewport0/scr/tabarnak/null.contentPane/null.layeredPane/JRootPane0/mainFrame"

And here is what the code try to read as the map key, in the SessionStorage::restoreTree method:

"table/JViewport0/scr/tabarnak"

Result : No saved state for...

--

Looks like I'll have to think of something else to save my tables... What BSAF save cannot be read again. So it's totally broken and unusable, and you can find proof in their forums... ;-(

kleopatra
Offline
Joined: 2003-06-11

strong words ... slightly disappointed, because I warned you: it's (most probably) a jdk version issue.

To verify, run the XTableApplication: it's saving/restoring the state just fine in jdk6, but not at all in jdk7. That's (again most probably, on the run right now) because the persistance delegates are no longer static, that is they have to be registered with each individual XMLEncoder instead of just once on startup of the application. So simply do so in a custom saveSession (or however the method is named in SwingXApplication, forgot)

Cheers
Jeanette

martinm1000
Offline
Joined: 2003-06-12

Hi Kleopatra.

Sorry, I was a little frustrated. But it is not your code that didn't work. Well my first try with your demo code didn't, but I understand its nature and it could have been my fault (you have many other support methods with that code).

What i did was to not even use your code for my 2nd try, and only the BSAF code for the column sizes. and this seems absolutely broken. So if your code is still based on the BSAF storage framework, i'm not sure it would work anyway... and seeing that this was reported on their forums years ago... ;-(

What we need is a solution for saving the state (and possibly the state of some specific components - ie we need more control than BSAF give us (How about a @SaveState on those JXTable and JXTreeTable definitions?)), which works on Java 6 and 7.

As for the XMLEncoder mess, personally I didn't even use that for serializing in my app, I use http://xstream.codehaus.org . Maybe this could be a solution since it looks like we cannot trust XMLEncoder...

szd116
Offline
Joined: 2012-01-05

kleopatra,
Please don't be disappointed. You guys have done a great job in both maintaining as well as developing swingx. We are very grateful, it's just that when things are not quite working and the deadline is approaching people could lose their equanimity. But my question is though, how come BFAF doesn't support JDK7 as well ? they are suppose to be the "better" one correct ? maybe I should post that in their form, but what the hack.

Thank you.

kleopatra
Offline
Joined: 2003-06-11

yeah, I understand deadline-induced nervousness :-) On the other hand: relying on unmaintained code like mine in the incubator _and_ expect it to work .... And: can't reproduce the problem with storing column width of a plain table. The following simply works in jdk7:

public final class ExamplePlainTable extends SingleFrameApplication {

    @Override
    public void startup() {
        show(buildTablePanel());
    }
   
    private JComponent buildTablePanel() {
        JTable table = new JTable(new AncientSwingTeam());
        table.setName("myTable");
        return new JScrollPane(table);
    }
   
    public static void main(String[] args) {
        launch(ExamplePlainTable.class, args);
    }
      
}

The issue with XProperties is that it relies on registering custom persistence delegates for the XXState beans. That was not a problem in earlier versions because the delegates were effectively static in scope: register them with any instance of a xmlEncolder did register them with all. That behaviour change did trigger heated debates ... because it would break existing code that depended on that (concededly half- or even undocumented) behaviour.

BSAF reacted by playing strictly to the core rules: the XState don't need an explicit delegate because they are fully behaved "beans" (as documented in PropertySupport) which are recognized automatically. My XStates are not (yet - will try to get those right asap). The way out is to take my code and fully beanify the XState, should be enough to add no-arg constructors and expose all properties by getters/setters.

HTH
Jeanette