Problems with grid

Hi!
I am facing problems with the following grid layout:

		grid.add(0, 0, 1, 1, component1);
		grid.add(0, 1, 1, 1, component2);
		grid.add(0, 2, 1, 1, component3);
		grid.add(1, 0, 1, 1, component4);
		grid.add(2, 0, 1, 1, component5);
		grid.add(2, 1, 1, 1, component6);```
This does not show any dockables allthough it shows them visible in the controller.
Something like this works fine:
```grid.add(0, 0, 1, 1, component1);
	grid.add(0, 1, 1, 1, component2);
	grid.add(0, 1, 1, 1, component3);
	grid.add(1, 0, 1, 2, component4);
	grid.add(2, 0, 1, 1, component5);
	grid.add(2, 1, 1, 1, component6);```
What is the magic behind it? Setting a 3 as width or height generally destroys the layout in a sense that either components are not visible or the whole layout is empty.

I know the first two numbers are the x- and y- coordinates, but how should I use the third and fourth numbers. I used to have them set to 1, 2 or 3, same as the weightx or weighty settings in a GridBagLayout. Is this correct? As they are doubles I would have suspected them to be so, but I entered e.g. 0.3 or 0.7 for two components in a column which destroyed the layout.
Another thing I have not yet understood is how a list of dockables can be assigned to the same location, especially a list of single dockables. I get the sense of multiple dockables as they tab automatically, but singles?
Thanks for your reply and best regards,
grml
  1. Comparing to a GridBagLayout, the 3. and 4. parameter would be gridwith and gridheight.

Imagine a sheet of paper on which you draw your layout. You draw a set of boxes (box = Dockable) preferrable such that they do not overlap and such that there are no empty spaces between them. Each box has a position and a size. The position is the 1. and 2. parameter („x“ and „y“), the size is the 3. and 4. parameter (hence they are called „width“ and „height“).
This sheet is the „grid“, and magically the sheet is big enough that all your boxes always fit in. :slight_smile:

Afterwards someone has a close look to this sheet, finds out how to organize the Dockables, and „deploys“ them (the grid has no use afterwards).

  1. As for the „list of dockables“: first of all, „add“ has a vararg-argument. You can just call something like:
    grid.add( 1, 2, 3, 4, dockable1, dockable2, dockable3 );
    … and second: if two Dockables have the exact some position and size, then they are also put together.

  2. The difference between single- and multiple-Dockables is how they are handled when the framework stores the layout (the position, size and relations between all elements).

  • Single-Dockable: just its identifier gets stored. The client is responsible for storing its content. Each single-Dockable has a unique identifier set by the client, no two dockables can share the same identifier.
  • Multiple-Dockable: the client has to provide a factory which is used to store the content of the Dockable. There can be many dockables for each factory, they are not unique.

Apart from that, single- and multiple-Dockables are handled exactly the same way everywhere (unless the client application treats the differently). It has nothing todo with tabs.

Btw.: if I run your settings the Dockables clearly appear. The framework might not always guess correctly how to fill empty spaces and resolve overlappings, but no component gets hidden or forgotten.

	public static void main( String[] args ){
		JFrame frame = new JFrame( "Demo" );
		CControl control = new CControl( frame );
		
		frame.add( control.getContentArea(), BorderLayout.CENTER );

		CGrid grid = new CGrid( control );
		grid.add( 0, 0, 1, 1, createDockable( "Red", Color.RED ) );
		grid.add( 0, 1, 1, 1, createDockable( "Green", Color.GREEN ) );
		grid.add( 0, 2, 1, 1, createDockable( "Blue", Color.BLUE ) );
		grid.add( 1, 0, 1, 1, createDockable( "Cyan", Color.CYAN ) );
		grid.add( 2, 0, 1, 1, createDockable( "Magenta", Color.MAGENTA ) );
		grid.add( 2, 1, 1, 1, createDockable( "Yellow", Color.YELLOW ) );
		
		control.getContentArea().deploy( grid );

		frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		frame.setBounds( 20, 20, 400, 400 );
		frame.setVisible( true );
	}

	public static SingleCDockable createDockable( String title, Color color ){
		JPanel panel = new JPanel();
		panel.setOpaque( true );
		panel.setBackground( color );
		return new DefaultSingleCDockable( title, title, panel );
	}
}```

Thanks Beni!
Do I understand the last two parameters correctly when I say that when e.g. width = 1 and height = 2 that the dockable spans over two rows or does it mean that the dockable is twice as high as wide?
This is important for me as I use the coded layout as default layout which is called by a “restore layout” button. It does then not read from the written data-files but from this layout. Therefore, I would like to be as flexible as possible to “initialize” the layout via code. Or are there easier solutions for that?
Thanks and best regards,
grml

The rows/column analogy is correct. And something like “width = 1.5” would mean 1 + a half row.

For your button that is certainly a valid solution. (Personally I prefer to store the “default layouts” in a file that never gets overridden, because then I can drag & drop my layout one time and don’t have to think about how to build it in code.)

OK. Thank you :slight_smile: That would mean anybody would have the possibility to delete the default layout files (when sHe finds them in the directories) which could cause an error when restoring that. I bypass that by trying to model the layout within the code.
Thanks for your input.
BTW: I have never mentioned how great your framework is. Congratulations and thanks for that and your superb support!
grml