0

我正在使用 Jgraphx 编写程序并且多项选择运行良好(我可以选择一个节点,按 ctrl 并单击另一个节点然后被选中),但我无法使选取框选择工作(我单击并拖动鼠标但是没有矩形出现来选择节点)。我做错了什么?

4

1 回答 1

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);
    }
}
于 2015-10-26T13:31:26.150 回答