Usage
Quick Start
To add docking to your Java Swing project, start by creating a DockingRegionRoot and add it to any Swing component:
public class DockingTestFrame extends javax.swing.JFrame { DockingRegionRoot dockPanel = new DockingRegionRoot(); public DockingTestFrame() { getContentPane().add(dockPanel, BorderLayout.CENTER); } }
You can new add Java Components to your docking area. This is done by wrapping them in a DockingContent class that provides your component to the docking manager, along with other useful information.
MyCustomJPanel panel = new MyCustomJPanel(); DockingContent cont = new DockingContent( "uniqueIdentifyingName", "Panel title", panel); dockPanel.getDockingRoot().addDockContent(cont);
When you create your DockingContent wrapper, you need to provide it with the information it needs to manage your component:
- uid - String uniquely identifying this component within the docking system. Used for saving and restoring docking layouts.
- title - String that is displayed in the tabbed pane that contains your component.
- icon - Optional icon to display to the left of the title.
- component - A Java component that will be used as the body of the docked window.
public DockingContent(String uid, String title, Component component); public DockingContent(String uid, String title, Icon icon, Component component);
Advanced Usage
The docking system manages a tree of windows. This structure is updated whenever the user drags and drops, maximizes, minimizes, floats or closes a window. It can also be updated programmatically by adding or removing DockingContent to subregions within the system.
Description of data structure
The DockingRegionRoot is the root of the system. It provides the root area inwhich content will be laid out. It also keeps track of all floating windows.
The DockingRegionRoot and all floating windows contain a DockingRegionContainer. The DockingRegionContainer is a rectangular region in which zero or more DockingContent will be laid out. The DockingRegionContainer also handles minimized and maximized windows. Minimized windows are displayed as buttons along the bottom of the DockingRegionContainer. When a DockingContent is maximized, it will take up the entire DockingRegionContainer until it is reduced in size again.
Within the DockingRegionContainer is a structure made of DockingContainers. Typically, this will consist of a tree of DockingRegionSplit with leaves of DockingRegionTabbed.
The DockingRegionSplit divides the workspace using either a horizontal or vertical JSplitPane. Each side of this split may contain child DockingChild, which can be either other DockingRegionSplit or DockingRegionTabbed.
A DockingRegionTabbed contains one or more DockingContent. If it has only one child, that child will take up the entire region. If there is more than one, tabs will be created to allow the user to easily switch between them.
Manpulating the tree
If you want to manually adjust the layout, you will need to start by getting the DockingRegionContainer from either the DockingRegionRoot or the floating window you're interested in. From there you can call getRoot() to get the lowest level child region in the container.
Once you have a DockingChild, you can navigate the tree by examining its children.
Regions which extend DockingContainer (ie, DockingRegionContainer, DockingRegionSplit) can add and remove split areas by calling split() and join().
You can add content to a DockingContainer using the split() method. You can add it to a DockingRegionTabbed with addTab().