Creating layout with use of CLocation

I want to create a layout that shown in wanted.jpg

My code sniplets:

    control = new CControl( this );
    CToolbarContentArea area = new CToolbarContentArea( control, "base" );
    control.addStationContainer( area );
    this.add(area);
   ......
  SingleCDockable dockableDetail = new DefaultSingleCDockable( "detail", "Details" );
  control.addDockable( dockableDetail );
  dockableDetail.setLocation( CLocation.base().normalRectangle( 0.0, 0.0, 0.45, 0.7) );
  dockableDetail.setVisible( true );
  
  SingleCDockable dockableProject = new DefaultSingleCDockable( "project", "Explorer" );
  control.addDockable( dockableProject );
  dockableProject.setLocation( CLocation.base().normalRectangle( 0.45, 0.0, 0.25, 0.7) );
  dockableProject.setVisible( true );
  
  SingleCDockable dockableFlags = new DefaultSingleCDockable( "flags", "Merkmale" );
  control.addDockable( dockableFlags );
  dockableFlags.setLocation( CLocation.base().normalRectangle( 0.7, 0.0, 0.2, 0.45) );
  dockableFlags.setVisible( true );
  
  SingleCDockable dockableImage = new DefaultSingleCDockable( "image", "Bild" );
  control.addDockable( dockableImage );
  dockableImage.setLocation( CLocation.base().normalRectangle( 0.7, 0.45, 0.15, 0.2) );
  dockableImage.setVisible( true );
  
  SingleCDockable dockableChildren = new DefaultSingleCDockable( "children", "Kinder" );
  control.addDockable( dockableChildren );
  dockableChildren.setLocation( CLocation.base().normalRectangle( 0.0, 0.7, 0.33, 0.3) );
  dockableChildren.setVisible( true );
  
  SingleCDockable dockableSiblings = new DefaultSingleCDockable( "siblings", "Geschwister" );
  control.addDockable( dockableSiblings );
  dockableSiblings.setLocation( CLocation.base().normalRectangle( 0.33, 0.7, 0.33, 0.3) );
  dockableSiblings.setVisible( true );
  
  SingleCDockable dockableAssociates = new DefaultSingleCDockable( "associates", "Assoziierte" );
  control.addDockable( dockableAssociates );
  dockableAssociates.setLocation( CLocation.base().normalRectangle( 0.66, 0.7, 0.33, 0.3) );
  dockableAssociates.setVisible( true );

What I get is shown in created.jpg

Where is the problem?

Thanks and regards

The code you have is adding one CDockable after the other. Each time a new CDockable is made visible space is taken from the other CDockables that are already visible.

In other words: the „location“ is only used to insert a dockable into the layout, not to keep its place.


A simple solution - under the condition that all CDockable objects are known when starting the app - would be using the CGrid. It is a class where dockables and their position/size are collected, and then all the dockables are made visible at the same time. Like in this example:

package test;

import javax.swing.JFrame;

import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.SingleCDockable;
import bibliothek.gui.dock.toolbar.CToolbarContentArea;

public class LayoutTest {
	public static void main( String[] args ) {
		JFrame frame = new JFrame( "Test" );
		frame.setBounds( 20, 20, 1000, 1000 );
		frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

		CControl control = new CControl( frame );
		CToolbarContentArea area = new CToolbarContentArea( control, "base" );
		control.addStationContainer( area );
		frame.add( area );

		SingleCDockable dockableDetail = new DefaultSingleCDockable( "detail", "Details" );
		SingleCDockable dockableProject = new DefaultSingleCDockable( "project", "Explorer" );
		SingleCDockable dockableFlags = new DefaultSingleCDockable( "flags", "Merkmale" );
		SingleCDockable dockableImage = new DefaultSingleCDockable( "image", "Bild" );
		SingleCDockable dockableChildren = new DefaultSingleCDockable( "children", "Kinder" );
		SingleCDockable dockableSiblings = new DefaultSingleCDockable( "siblings", "Geschwister" );
		SingleCDockable dockableAssociates = new DefaultSingleCDockable( "associates", "Assoziierte" );

		CGrid grid = new CGrid( control );

		// row 1
		grid.add( 0, 0, 45, 70, dockableDetail );
		grid.add( 45, 0, 25, 70, dockableProject );
		grid.add( 70, 0, 20, 45, dockableFlags );
		grid.add( 70, 45, 20, 25, dockableImage );
		
		// row 2
		grid.add( 0, 70, 33, 30, dockableChildren );
		grid.add( 33, 70, 33, 30, dockableSiblings );
		grid.add( 66, 70, 33, 30, dockableAssociates );
		
		// make everything visible
		area.deploy( grid );
		
		frame.setVisible( true );
	}
}

If you want to get more crazy: the entire layout, including history of visible, invisible and not-yet-known CDockables can be set up with the CPerspective layout. You might start by looking at the PerspectivesIntroduction, PerspectivesMulti and PerspectivesHistory classes from the tutorial project.

Thanks. I think for the time being I will stay with the solution „as is“ and probably save the desired layout by control.writeXML() and reload it by control.readXML() at the startup of the app.

Trying CPerspective I will postpone for later investigations.