我是实现UML里面各种箭头
用  Polygon画的 拖动位置就变了 
求源代码

解决方案 »

  1.   

    建议你看一下jgraph的源码,里面有你想要的部分
      

  2.   

    JGRAPH吧。它里面可以为edge的端点选择不同的形状。
    自带的helloworld里就可以看到。public class HelloWorld { public static void main(String[] args) { // Construct Model and Graph
    GraphModel model = new DefaultGraphModel();
    JGraph graph = new JGraph(model); // Control-drag should clone selection
    graph.setCloneable(true); // Enable edit without final RETURN keystroke
    graph.setInvokesStopCellEditing(true); // When over a cell, jump to its default port (we only have one, anyway)
    graph.setJumpToDefaultPort(true); // Insert all three cells in one call, so we need an array to store them
    DefaultGraphCell[] cells = new DefaultGraphCell[3]; // Create Hello Vertex
    cells[0] = createVertex("Hello", 20, 20, 40, 20, null, false); // Create World Vertex
    cells[1] = createVertex("World", 140, 140, 40, 20, Color.ORANGE, true); // Create Edge
    DefaultEdge edge = new DefaultEdge();
    // Fetch the ports from the new vertices, and connect them with the edge
    edge.setSource(cells[0].getChildAt(0));
    edge.setTarget(cells[1].getChildAt(0));
    cells[2] = edge; // Set Arrow Style for edge
    int arrow = GraphConstants.ARROW_CLASSIC;
    GraphConstants.setLineEnd(edge.getAttributes(), arrow);
    GraphConstants.setEndFill(edge.getAttributes(), true); // Insert the cells via the cache, so they get selected
    graph.getGraphLayoutCache().insert(cells); // Show in Frame
    JFrame frame = new JFrame();
    frame.getContentPane().add(new JScrollPane(graph));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
    } public static DefaultGraphCell createVertex(String name, double x,
    double y, double w, double h, Color bg, boolean raised) { // Create vertex with the given name
    DefaultGraphCell cell = new DefaultGraphCell(name); // Set bounds
    GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(
    x, y, w, h)); // Set fill color
    if (bg != null) {
    GraphConstants.setGradientColor(cell.getAttributes(), bg);
    GraphConstants.setOpaque(cell.getAttributes(), true);
    } // Set raised border
    if (raised)
    GraphConstants.setBorder(cell.getAttributes(), BorderFactory
    .createRaisedBevelBorder());
    else
    // Set black border
    GraphConstants.setBorderColor(cell.getAttributes(), Color.black); // Add a Floating Port
    cell.addPort(); return cell;
    }}注意这里:
    // Set Arrow Style for edge
    int arrow = GraphConstants.ARROW_CLASSIC; //设置arrow的样式,要菱形可改为ARROW_DIAMOND;
    GraphConstants.setLineEnd(edge.getAttributes(), arrow); //设置edge的end端点的形状;你还可以setLineBegin();
    GraphConstants.setEndFill(edge.getAttributes(), true); //设置是否绘制edge的两个端点;因为Jgraph是基于Swing JComponent设计的,port、edge是固定在cell上的某处的,拖动cell时不会跑动。当然,你也可以设置为活动的节点。不知道有没有误解LZ的意思~
      

  3.   

    jgraph 那个菱形画得也不好,
    我有点不明白jgraph里面的GraphConstants.setLineEnd(edge.getAttributes(), arrow);
    这个方法, 
    DefaultGraphCell[] cells = new DefaultGraphCell[3];cells里面放控件 比如放是两个JInternalFrame之间画的菱形 ??有jgraph经验的我们可以交流交流