« prev next »
Java Docking Home> Developer Guide> How to Add, Move, and Remove Dockables

How to Add, Move, and Remove Dockables

:: Adding, moving and removing dockables ::

If you want to add, move or remove a dockable, you can use the methods from Dock, LeafDock, and CompositeDock:

A better possibility is to use one of the following methods from the DockingExecutor:

The docking executor fires also a DockableEvent on the dockable. An event is fired before and after the docking change. Once there are listeners in your application that listen to dockable events, you should always use the methods from the docking executor.

With the docking executor you can combine a removal and an addition. If you use the method changeDocking() for a dockable that is already docked in a dock, the dockable is removed from its old dock, before adding it to the new dock. An event is fired before the removal of the dockable and after the addition of the dockable.

:: Closing and restoring dockables with a dockable state action ::

The easiest way to close and restore a dockable is using a DefaultDockableStateAction. These actions are doing everything for you:

			closeAction = new DefaultDockableStateAction(dockable, DockableState.CLOSED);
			restoreAction = new DefaultDockableStateAction(dockable, DockableState.NORMAL);
		public void itemStateChanged(ItemEvent itemEvent)
			if (itemEvent.getStateChange() == ItemEvent.DESELECTED)
				// Close the dockable.
				closeAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Close"));
				// Restore the dockable.
				restoreAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Restore"));
When a dockable is closed with a dockable state action, a DockingPath is created for the dockable. This docking path is added to the DockingPathModel of the docking manager. When the dockable is restored, the docking path is used to restore the dockable as good as possible where the dockable was docked before.

If you want to restore a dockable that was not already docked, you better add first a docking path for the dockable to the docking path model by your self (see How to Use Docking Paths).

The source code of the samples can be found in:

CodecExampleShows the usage, the encoding, and the decoding of dock models.
WorkspaceExampleShows the usage, the encoding, and the decoding of dock models.

« prev next »