如果你要添加一个用户界面功能对接组件,您必须创建一个可Dockable它。 您的组件作为内容的可停靠。
在第一个参数的DefaultDockable是可停靠的ID。应用程序标识您所有的dockables中应有所不同。// Create the content component.创建内容的组成部分。TextPanel textPanel = new TextPanel("I am window 1.");// Create the dockable around the content component.创建可停靠约的内容组成部分。Dockable dockable = new DefaultDockable("Window1", textPanel, "Window", null, DockingMode.ALL);
你可以考虑到可停靠的图标和描述。图标将显示在停靠的是头码头,可停靠的地方。该说明将显示为工具提示头以上。
// Create the dockable around the content component.创建可停靠约的内容组成部分Icon icon = new ImageIcon(getClass().getResource("/com/javadocking/resources/images/text12.gif"));DefaultDockable dockable = new DefaultDockable("Window1", textPanel, "Window", icon);dockable.setDescription("Window with text");
您可以指定在什么样的停靠船坞可以通过设置模式对接对接。不同的对接模式是类定义在DockingMode 。
在下例中例如dockables不能自由浮动。
// We don't want the dockables to float.我们不希望dockables浮动。int dockingModes = DockingMode.ALL - DockingMode.FLOAT;// Create the dockables around the content components.创建dockables围绕内容的组成部分。Dockable dockable = new DefaultDockable("Window1", textPanel, "Window", icon, dockingModes);
你可以装点一个使用一个可停靠的行动, ActionDockable 。首先,你必须创建您的基本可停靠。 然后你创建包装器周围可停靠停靠行动,这增加了它的行动。
在folowing例如可停靠第一次装饰结束行动。然后是行动与另外2个装饰。
// Create the dockable around the content component./ /创建可停靠约的内容组成部分。Dockable dockable = new DefaultDockable("Window1", textPanel, "Window", new ImageIcon("resources/images/text12.gif"));// Decorate the dockable with a close action./ /装饰用紧密行动停靠。dockable = new StateActionDockable(dockable, new DefaultDockableStateActionFactory(), DockableState.STATES_CLOSED);// Decorate the dockable with another action./ /装饰与另一行动停靠MessageAction helloAction = new MessageAction(this, "Hello", new ImageIcon("/com/javadocking/resources/images/hello12.gif"), "Hello world!");MessageAction cautionAction = new MessageAction(this, "Caution", new ImageIcon("/com/javadocking/resources/images/caution12.gif"), "Be Careful!");Action[][] actions = new Action[1][];actions[0] = new Action[2];actions[0][0] = helloAction;actions[0][1] = cautionAction;dockable = new ActionDockable(dockable, actions);
一个可停靠总是可以拖拖头的码头,其中停靠。这也可以拖动其内容可停靠拖动。
如果你想要那个,界面内容您可停靠应执行DraggableContent 。该接口包含一个方法addDragListener(DragListener)。 拖动侦听应该加入能够为鼠标拖动可停靠的听众和鼠标运动监听每个组件与您想要的。
A possible implementation is:一种可能的实现是:
public void addDragListener(DragListener dragListener){this.addMouseListener(dragListener);this.addMouseMotionListener(dragListener);label.addMouseListener(dragListener);label.addMouseMotionListener(dragListener);}
SimpleDockable SimpleDockable | Shows a simple dockable.显示了一个简单的可停靠。 |
IconDockable IconDockable | Shows a dockable with an icon and tooltip.显示了一个图标和一个可停靠的工具提示。 |
NotFloatingDockable NotFloatingDockable | Shows a dockable that cannot float.显示了一个可停靠的,不能自由浮动。 |
ActionsDockable ActionsDockable | Shows a dockable with actions.以行动显示了可停靠。 |
联系客服