gpt4 book ai didi

java - JGraphX 中的 JTree

转载 作者:行者123 更新时间:2023-12-01 14:48:59 25 4
gpt4 key购买 nike

在 EditorPalette 中,模板使用 JLabels 表示,可以将其拖放到 mxGraphComponent 中,对吗?

但是,我想通过JTree使用层次结构将这些模板添加到EditorPalette中,并且不能像普通模板一样在GraphComponents中拖放节点

您能帮我提供一个添加模板的功能,用于在组件左侧添加 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);
}

关于java - JGraphX 中的 JTree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15079851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com