Skip to main content

How I can save the dimensions of the JXMultiSplitPane?

2 replies [Last post]
josecursotsm
Offline
Joined: 2013-03-11
Points: 0

I'm experimenting with and I can not figure out JXMultiSplitPane as keeping
the dimensions to change.

I had tried to save the full model, but I've found that does not implement
the Serializable interface, so this method does not work because it causes
serialization failure.

 public static abstract class Node{
    ...
}

Does anyone shedding light on this dilemma?
sorry for my language

Edit:
Thanks to "martinm1000"
from making-layouts-persistent
I leave here JXMultiSplitPane wrap if someone serves.
If you find a bug, or is not an elegant solution, please indicate to fix it.
regards

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.jdesktop.swingx.JXMultiSplitPane;
import org.jdesktop.swingx.MultiSplitLayout;
import org.jdesktop.swingx.MultiSplitLayout.Node;


public class JXMultiSplitPaneWrapper extends JXMultiSplitPane {

public JXMultiSplitPaneWrapper(){
    super();
}

public JXMultiSplitPaneWrapper(final MultiSplitLayout layout){
super(layout);
}
 
public void saveModelXML(final String xmlPath){
XMLEncoder e = null;
try {
e = new XMLEncoder(new BufferedOutputStream(
            new FileOutputStream(xmlPath)));
Node model = this.getMultiSplitLayout().getModel();
e.writeObject(model);
} catch (Exception ex) {
ex.printStackTrace();
}finally{
try {
if(e != null)e.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}

public void setModelXML(final String xmlPath, final String layoutDef){
    XMLDecoder d = null;
try {
    d = new XMLDecoder(new BufferedInputStream(
            new FileInputStream(xmlPath)));
    Node model = (Node)(d.readObject());
    this.getMultiSplitLayout().setModel(model);
    this.getMultiSplitLayout().setFloatingDividers(false);
}catch (Exception exc) {
    Node model = MultiSplitLayout.parseModel(layoutDef);
    this.getMultiSplitLayout().setModel(model);
}finally{
try {
    if(d != null)d.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

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
Points: 0

From memory... can you check if this works ?

getModel().toString() & Node.parse

Edit: http://today.java.net/pub/a/today/2006/03/23/multi-split-pane.html

josecursotsm
Offline
Joined: 2013-03-11
Points: 0

The method getModel().toString() returns:
MultiSplitLayout.Split "null" COLUMN [3 children] java.awt.Rectangle[x=4,y=4,width=986,height=503]
and when applied directly, not successful

I will continue investigating later,
although it seems that would have to scroll through nodes and storing values ​​of each or something.

thank you very much for your time
regards

Edit:
It works!:
http://today.java.net/pub/a/today/2006/03/23/multi-split-pane.html#making-layouts-persistent

thanks again!