Java JGraphX中的JTree
在EditorPalette中,模板使用jLabel表示,jLabel可以在mxGraphComponent中拖放,对吗 但是,我想通过JTree使用层次结构将这些模板添加到EditorPalette中,并且不能像普通模板那样在GraphComponents中拖放节点Java JGraphX中的JTree,java,jgraphx,Java,Jgraphx,在EditorPalette中,模板使用jLabel表示,jLabel可以在mxGraphComponent中拖放,对吗 但是,我想通过JTree使用层次结构将这些模板添加到EditorPalette中,并且不能像普通模板那样在GraphComponents中拖放节点 你能帮我提供一个添加模板的功能,在组件左侧添加JTree并在mxGraphComponent上拖放吗?好的,我知道了。我的错误是,我必须创建一个mxCell来提供几何信息,所以 mxCell cell = new mxCell(c
你能帮我提供一个添加模板的功能,在组件左侧添加JTree并在mxGraphComponent上拖放吗?好的,我知道了。我的错误是,我必须创建一个mxCell来提供几何信息,所以
mxCell cell = new mxCell(component);
在上面的代码中,我必须编写
mxCell cell = new mxCell(component, new mxGeometry(), "");
添加拖动功能的完整方法如下所示:
public void addComponentTabListeners() {
final JTree componentTree = view.componentTree;
DragGestureListener dragGestureListener = new DragGestureListener() {
@Override
public void dragGestureRecognized(DragGestureEvent arg0) {
TreePath path = componentTree.getSelectionPath();
if ((path == null) || (path.getPathCount() <= 1)) {
return;
}
DefaultMutableTreeNode componentsNode = (DefaultMutableTreeNode) path.getLastPathComponent();
I_Component component = null;
try {
component = ComponentHandler_KonsensApplication.getInstance().createInstance(
componentsNode.toString(), "need unique Name here");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
mxCell cell = new mxCell(component, new mxGeometry(), "");
cell.setVertex(true);
mxRectangle bounds = new mxRectangle();
bounds.setHeight(80);
bounds.setWidth(80);
mxGraphTransferable t = new mxGraphTransferable(new Object[] { cell }, bounds);
arg0.startDrag(null, mxSwingConstants.EMPTY_IMAGE, new Point(), t, null);
}
};
DragSource dragSource = new DragSource();
dragSource.createDefaultDragGestureRecognizer(componentTree, DnDConstants.ACTION_COPY,
dragGestureListener);
}
public void addComponentTableListeners(){
最终JTree componentTree=view.componentTree;
DragGestureListener DragGestureListener=新的DragGestureListener(){
@凌驾
公共无效DragestureRecognited(DragestureEvent arg0){
TreePath=componentTree.getSelectionPath();
if((path==null)| |(path.getPathCount()