Having a Split Dock Station under a Stack Dock Station

Hello Everybody

I would like to know if it is possible using the common library, to have a split dock station containing two dockables under a stack dock station. If it is possible, Can you tell me how it is done because i couldn’t find a way to implement it.

Many thanks in advance,

I’m not sure what exactly you want, what means “under”?

It might be necessary to implement the CStation interface for StackDockStation if you want to use it as root, the rest might need some tricks but should work. I can write you some code (assuming I understood your question as you intended).

Hello Beni and thanks for your quick answer

I have attached you two images of what i would like to have. For the moment i can obtain this result but using multiple CControls. And i would like to obtain this kind of screens and even a more complex one with multiple StackDockStations holding multiple splitDockstations and StackDockStations…

Can you help me on this issue, some code telling me how to do it would be very helpful


You can create some "CGridArea"s, which are just SplitDockStations, and drop them into the layout. You need to subclass them and override “isStackable” to allow them being in the same stack (otherwise some exceptions are thrown when you try to build the layout). The framework will never remove these stations automatically. Also the user cannot remove them or add new ones, which might be frustrating for some users…

You might also be interested in the CWorkingArea, which is a subclass of CGridArea. If any dockable is dropped on the CWorkingArea it cannot be dragged outside. Its behavior is like the panel on Eclipse where all the editors (the source file views) open.

(Btw.: I noticed an exception when grabbing a tab, exept an update in the next few days)

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.CGridArea;
import bibliothek.gui.dock.common.CLocation;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.SingleCDockable;
import bibliothek.gui.dock.common.mode.ExtendedMode;

public class Dock8 {
	private static class StackableCGridArea extends CGridArea{
		public StackableCGridArea( CControl control, String id ){
			super( control, id );
		public boolean isStackable(){
			return true;
	public static CGridArea createGridArea( String id, CControl control ){
		CGridArea area = new StackableCGridArea( control, id );
		area.setTitleShown( true );
		area.setTitleText( id );
		control.add( area );
		control.add( area, true );
		return area;
	public static SingleCDockable createDockable( String title, Color color ){
		JPanel panel = new JPanel();
		panel.setOpaque( true );
		panel.setBackground( color );
		DefaultSingleCDockable dockable = new DefaultSingleCDockable( title, title, panel );
		dockable.setDefaultLocation(ExtendedMode.MINIMIZED, CLocation.base().minimalEast());
		dockable.setDefaultLocation(ExtendedMode.EXTERNALIZED, CLocation.external( 0, 0, 300, 300 ));
		return dockable;
	public static void main( String[] args ){
		SwingUtilities.invokeLater( new Runnable() {
			public void run(){
				JFrame frame = new JFrame( "Demo" );
				CControl control = new CControl( frame );
				frame.add( control.getContentArea(), BorderLayout.CENTER );

				CGridArea gridArea1 = createGridArea( "grid 1", control );
				CGridArea gridArea2 = createGridArea( "grid 2", control );
				CGrid grid = new CGrid( control );
				grid.add( 0, 0, 1, 2, gridArea1, gridArea2 );
				grid.add( 1, 0, 1, 1, createDockable( "Green", Color.GREEN ) );
				grid.add( 1, 1, 1, 1, createDockable( "Blue", Color.BLUE ) );
				control.getContentArea().deploy( grid );
				CGrid grid1 = new CGrid( control );
				grid1.add( 0, 0, 1, 1, createDockable( "Red", Color.RED ) );
				grid1.add( 0, 1, 1, 1, createDockable( "Yellow", Color.YELLOW ) );
				gridArea1.deploy( grid1 );
				CGrid grid2 = new CGrid( control );
				grid2.add( 0, 0, 1, 1, createDockable( "Cyan", Color.CYAN ) );
				grid2.add( 0, 1, 1, 1, createDockable( "Magenta", Color.MAGENTA ) );
				gridArea2.deploy( grid2 );
				frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
				frame.setBounds( 20, 20, 400, 400 );
				frame.setVisible( true );

Thanks you Beni for your prompt answer, It helped me a lot.

Thanks for posting this Beni. :slight_smile: This has also helped me in my project. Maybe this example should also be included in the tutorial.

That is a good idea, I’ll put it on the todo list :wink: