If you need a button that can be moved in its tool bar, that can be dragged to other tool bars, or that can be made floating, you have to create a ButtonDockable around your button:
You can also use other components in the button dockable:// Create the button. JButton button = new JButton(action); // Create the dockable with the button as component. ButtonDockable buttonDockable = new ButtonDockable(id, button);
The main difference between button dockables and normal dockables is their docking mode:// Create the button. ToolBarButton button = new ToolBarButton(action); // Create the dockable with the button as component. ButtonDockable buttonDockable = new ButtonDockable(id, button);
The normal docks don't accept the docking modes of a button dockable, so button dockables will not be docked in these docks. Their are special docks that accept the docking modes for button dockables.// Create the dockable with the button as component and that can't float. ButtonDockable buttonDockable = new ButtonDockable(id, button, DockingMode.TOOL_BAR);
Button dockables can also not be maximized or minimized.
You can create a horizontal or vertical LineDock for buttons like this:
The third parameter is the docking mode that is used when the orientation is horizontal, the fourth parameter is the docking mode that is used when the orientation is vertical.LineDock toolBarDock1 = new LineDock(LineDock.ORIENTATION_HORIZONTAL, false, DockingMode.HORIZONTAL_TOOLBAR, DockingMode.VERTICAL_TOOLBAR); ... LineDock toolBarDock5 = new LineDock(LineDock.ORIENTATION_VERTICAL, false, DockingMode.HORIZONTAL_TOOLBAR, DockingMode.VERTICAL_TOOLBAR);
You can create a GridDock for buttons like this:
GridDock toolGridDock = new GridDock(DockingMode.TOOL_GRID);
You can create a horizontal or vertical CompositeLineDock for buttons like this:
Add the line docks with the button dockables:CompositeLineDock compositeToolBarDock1 = new CompositeLineDock(CompositeLineDock.ORIENTATION_HORIZONTAL, false, new ToolBarDockFactory(), DockingMode.HORIZONTAL_TOOLBAR, DockingMode.VERTICAL_TOOLBAR); CompositeLineDock compositeToolBarDock2 = new CompositeLineDock(CompositeLineDock.ORIENTATION_VERTICAL, false, new ToolBarDockFactory(), DockingMode.HORIZONTAL_TOOLBAR, DockingMode.VERTICAL_TOOLBAR);
You can create a BorderDock for tool bars like this:compositeToolBarDock1.addChildDock(toolBarDock1, new Position(0)); compositeToolBarDock1.addChildDock(toolBarDock2, new Position(1)); compositeToolBarDock1.addChildDock(toolBarDock3, new Position(2)); compositeToolBarDock1.addChildDock(toolBarDock4, new Position(3)); compositeToolBarDock2.addChildDock(toolBarDock5, new Position(0)); compositeToolBarDock2.addChildDock(toolBarDock6, new Position(1)); compositeToolBarDock2.addChildDock(toolBarDock7, new Position(2));
If this dock is the root dock, it has to be added to the DockModel:BorderDock toolBarBorderDock = new BorderDock(new CompositeToolBarDockFactory(), splitDock); toolBarBorderDock.setMode(BorderDock.MODE_TOOL_BAR);
Add the composite line docks at the borders:dockModel.addRootDock("borderDock", toolBarBorderDock, frame);
toolBarBorderDock.setDock(compositeToolBarDock1, Position.TOP); toolBarBorderDock.setDock(compositeToolBarDock2, Position.LEFT);
JButtonExample | Shows JButtons in a tool bar at the borders of a window. |
ToolBarButtonExample | Shows custom buttons in a tool bar at the borders of a window and in a floating grid. |