I’m new to docking frames, so this is likely a noob question. But I would like to setup a default layout (which I currently did using a perspective), but keep some dockables hidden at start, and allow them to be toggled through a menu (after which they appear at the destination I set). However, if they are added to a perspective, they become visible when this perspective is loaded. For the toggling I tried borrowing from the notes example using the DockFrontend, but as soon as i hide a dockable, I can’t add it anymore because it has no default station (?) … Anyway, some pointers would be appreciated.
Hi. This is possible with the Common API. I’ll send you a nice example and some explanations on the weekend (I’m currently working on another project whose release date is very close…)
Regards
Beni
Alright, finally an answer.
- Please update to 1.1.2p2a, otherwise the example will not work as intended (sorry for that, I needed to fix a bug first)
- And start using the Common API, simply because it is much easier:
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.menu.SingleCDockableListMenuPiece;
import bibliothek.gui.dock.common.perspective.CGridPerspective;
import bibliothek.gui.dock.common.perspective.CPerspective;
import bibliothek.gui.dock.common.perspective.SingleCDockablePerspective;
import bibliothek.gui.dock.facile.menu.RootMenuPiece;
public class HiddenDockable {
public static void main(String[] args) {
// create a frame, a CControl and some dockables...
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final CControl control = new CControl( frame );
frame.add(control.getContentArea());
DefaultSingleCDockable dockableA = new DefaultSingleCDockable("a", "Aaaa");
DefaultSingleCDockable dockableB = new DefaultSingleCDockable("b", "Bbbb");
DefaultSingleCDockable dockableC = new DefaultSingleCDockable("c", "Cccc");
dockableA.setCloseable(true);
dockableB.setCloseable(true);
dockableC.setCloseable(true);
control.addDockable(dockableA);
control.addDockable(dockableB);
control.addDockable(dockableC);
// this is the interesting part, here we create the layout
setupLayout(control);
// and we add a menu to easily open and close the dockables
JMenuBar menubar = new JMenuBar();
SingleCDockableListMenuPiece menu = new SingleCDockableListMenuPiece(control);
menubar.add(new RootMenuPiece("Panels", false, menu).getMenu());
frame.setJMenuBar(menubar);
frame.setBounds(20, 20, 400, 400);
frame.setVisible(true);
}
private static void setupLayout( CControl control ){
// we start with a new, empty layout
CPerspective perspective = control.getPerspectives().createEmptyPerspective();
// ... accessing the middle of the frame ...
CGridPerspective center = perspective.getContentArea().getCenter();
// These are placeholders pointing to the real dockables
SingleCDockablePerspective dockableA = new SingleCDockablePerspective("a");
SingleCDockablePerspective dockableB = new SingleCDockablePerspective("b");
SingleCDockablePerspective dockableC = new SingleCDockablePerspective("c");
// We add the placeholders as if they were normal dockables
center.gridAdd(0, 0, 1, 1, dockableA);
center.gridAdd(1, 0, 1, 1, dockableB, dockableC);
// Then we save the current layout
center.gridDeploy();
// And now we remove the placeholders from the layout.
dockableA.remove();
dockableB.remove();
dockableC.remove();
// We now have some empty stacks in the layout, "shrink" will remove them for us
perspective.shrink();
// And now we save the layout a second time. The objects we removed are kept as real placeholders now
control.getPerspectives().setPerspective(perspective, true);
}
}
thanks for the fast answer Beni. I was going to try it tonight, but was unable to pull the 1.1.2-snapshot from the maven repository at https://oss.sonatype.org/content/repositories/snapshots/org/dockingframes/. Is it possible to publish the 1.1.2 snapshots there too?
Maven is the realm of Andrei, best ask him directly. But I would wait another 24 hours or so, his script should detect changes in the git repository automatically but with some delay.