0

I'm writting a program using Jgraphx and the multiple selection works well (I can select one node, press ctrl and click on other node and is selected then), but I cannot make the marquee selection works (I click and drag the mouse but no rectangle appears to select nodes). What I'm doing wrong?

yoprogramo
  • 1,306
  • 9
  • 14

1 Answers1

2

To add this functionallity create a new mxRubberband. This will do all the work for you. Example:

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);
    }
}
F. Lumnitz
  • 688
  • 4
  • 11