首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JGraphX中的JTree

JGraphX中的JTree
EN

Stack Overflow用户
提问于 2013-02-26 09:36:57
回答 1查看 330关注 0票数 0

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

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

你能帮我在组件的左侧添加JTree和在mxGraphComponent上拖放的add template功能吗?

EN

回答 1

Stack Overflow用户

发布于 2013-08-31 02:34:49

好的,我知道了。我的错误是,我必须创建一个提供几何信息的mxCell,而不是

代码语言:javascript
复制
mxCell cell = new mxCell(component);

在上面的代码中,我必须写

代码语言:javascript
复制
mxCell cell = new mxCell(component, new mxGeometry(), "");

添加拖动功能的完整方法如下所示:

代码语言:javascript
复制
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);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15079851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档