You found a bug: it is a focus issue! Because during loading of the layout the theme gets updated, the stack did request focus for its newest child - and the framework did handle the request by making sure that child is visible, which required a change of the maximized Dockable.
I have fixed that behavior in the newest version, 1.1.2p9d. You can download it from here.
Btw.: your application using the Common API. Notice the additional features like minimizing and floating Dockables…
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
public class DockingFrameTest extends JFrame {
File xmlFile = null;
CControl control;
DefaultSingleCDockable dockable1;
DefaultSingleCDockable dockable2;
DefaultSingleCDockable dockable3;
DefaultSingleCDockable dockable4;
DefaultSingleCDockable dockable5;
public DockingFrameTest() {
setTitle("Test Docking");
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
setVisible(false);
dispose();
System.exit(0);
}
});
setPreferredSize(new Dimension(800, 600));
init();
pack();
}
private void init() {
xmlFile = new File("layout.xml");
control = new CControl( this );
// you need this additional line if you want to enable loading of maximized Dockable
control.setRevertToBasicModes( false );
add( control.getContentArea() );
dockable1 = new DefaultSingleCDockable("dock1", "dock 1", new JLabel("Dockable 1"));
dockable2 = new DefaultSingleCDockable("dock2", "dock 2", new JLabel("Dockable 2"));
dockable3 = new DefaultSingleCDockable("dock3", "dock 3", new JLabel("Dockable 3"));
dockable4 = new DefaultSingleCDockable("dock4", "dock 4", new JLabel("Dockable 4"));
dockable5 = new DefaultSingleCDockable("dock5", "dock 5", new JLabel("Dockable 5"));
CGrid grid = new CGrid( control );
grid.add(0, 0, 60, 50, dockable1);
grid.add(60, 0, 40, 50, dockable2);
grid.add(0, 50, 60, 50, dockable3);
grid.add(60, 50, 40, 50, dockable4);
grid.add(60, 50, 40, 50, dockable5);
control.getContentArea().deploy( grid );
// don't need that
// loadLayout();
}
private void loadLayout() {
try {
control.readXML( xmlFile );
} catch (Exception e) {
e.printStackTrace();
}
}
private void saveLayout() {
try {
control.writeXML( xmlFile );
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Layout saved " + xmlFile.getAbsolutePath());
}
@Override
public void setVisible(boolean b) {
if (b) {
loadLayout();
} else {
saveLayout();
}
super.setVisible(b);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
DockingFrameTest frame = new DockingFrameTest();
if (frame != null) {
frame.setVisible(true);
} else {
System.exit(0);
}
}
});
}
}```