Hi,
I tried to save the last layout when closing window. But the workingArea is always invisible when reloading the last layout.
There might be something wrong in the following code. Could you please help?
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JFrame;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CWorkingArea;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
public class SaveLayout extends JFrame {
private CControl control;
private String lastLayoutPath = "C:\\Users\\TDF40\\Desktop\\lastLayout.xml";
public SaveLayout() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(20, 20, 400, 400);
control = new CControl(this);
add(control.getContentArea());
DefaultSingleCDockable dockable = new DefaultSingleCDockable("d1","Title1");
control.addDockable(dockable);
dockable.setVisible(true);
CWorkingArea work = control.createWorkingArea("workingArea");
work.setVisible(true);
DefaultSingleCDockable dockable2 = new DefaultSingleCDockable("d2","Title2");
control.addDockable(dockable2);
dockable2.setVisible(true);
// loadLastLayout();
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
control.destroy();
saveCurrentLayout();
}
});
}
public boolean loadLastLayout() {
try {
File file = new File(lastLayoutPath);
if (file.exists()) {
control.readXML(file);
control.load("lastLayout", true);
return true;
} else
return false;
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
public void saveCurrentLayout() {
try {
control.save("lastLayout", true);
control.writeXML(new File(lastLayoutPath));
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
SaveLayout frame = new SaveLayout();
}
}