选框选择对Jgraphx不起作用

时间:2015-10-26 10:34:42

标签: jgraphx jgraph

我正在使用Jgraphx编写程序并且多项选择效果很好(我可以选择一个节点,按ctrl然后单击其他节点然后选中),但是我无法使选框选择起作用(我点击并拖动鼠标但没有矩形似乎选择节点)。我做错了什么?

1 个答案:

答案 0 :(得分:2)

要添加此功能,请创建一个新的mxRubberband。这将为您完成所有工作。 例如:

public class HelloWorld extends JFrame
{
    private static final long serialVersionUID = -2707712944901661771L;

    public HelloWorld()
    {
        super("Hello, World!");

        mxGraph graph = new mxGraph();
        Object parent = graph.getDefaultParent();

        graph.getModel().beginUpdate();
        try
        {
            String s1 = "Hello";
            String s2 = "World!";
            Object v1 = graph.insertVertex(parent, "ID1", s1, 20, 20, 80,
                    30);
            //graph.insertVertex(parent, null, v1, 20, 280, 80, 30);
            Object v2 = graph.insertVertex(parent, "ID2", s2, 240, 150,
                    80, 30);
            mxCell edge = (mxCell) graph.insertEdge(parent, "ID3", "TEST", v1, v2);

        }
        finally
        {
            graph.getModel().endUpdate();
        }
        Object o = graph.getDefaultParent();
        mxGraphComponent graphComponent = new mxGraphComponent(graph);
        new mxRubberband(graphComponent); // Adds support for marquee selection

        getContentPane().add(graphComponent);

    }

    public static void main(String[] args)
    {
        HelloWorld frame = new HelloWorld();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 320);
        frame.setVisible(true);
    }
}