有个需求,jgraph后台生成了流程图,但是要放在JSP页面上展示,希望各位朋友能多支持,不吝赐教,万分感谢!!

解决方案 »

  1.   

    不是太了解Jgraph,你查查api有没有可以输出为io流的东西?
    servlet做io流输出,jsp里面用<image src="servlet"/>就行。
      

  2.   

    我用过两种方案,一是applet,一是生成静态图片。jbpm有生成静态图片的例子,可以参考
      

  3.   

    请指教,我对Applet不了解 请问哪里写错了,我怎么显示不出来啊在页面
    public class HelloWorld extends Applet{
    public static void main(String[] args) {
    GraphModel model = new DefaultGraphModel();
    GraphLayoutCache view = new GraphLayoutCache(model,
    new
    DefaultCellViewFactory());
    JGraph graph = new JGraph(model, view);
    DefaultGraphCell[] cells = new DefaultGraphCell[3];
    cells[0] = new DefaultGraphCell(new String("Hello")); GraphConstants.setBounds(cells[0].getAttributes(), new
    Rectangle2D.Double(20,20,40,20));
    GraphConstants.setGradientColor(
    cells[0].getAttributes(),
    Color.orange);
    GraphConstants.setOpaque(cells[0].getAttributes(), true);
    DefaultPort port0 = new DefaultPort();
    cells[0].add(port0);
    cells[1] = new DefaultGraphCell(new String("World")); GraphConstants.setBounds(cells[1].getAttributes(), new
    Rectangle2D.Double(140,140,40,20));
    GraphConstants.setGradientColor(
    cells[1].getAttributes(),
    Color.red);
    GraphConstants.setOpaque(cells[1].getAttributes(), true);
    DefaultPort port1 = new DefaultPort();
    cells[1].add(port1);
    DefaultEdge edge = new DefaultEdge();
    edge.setSource(cells[0].getChildAt(0));
    edge.setTarget(cells[1].getChildAt(0));
    cells[2] = edge;
    int arrow = GraphConstants.ARROW_CLASSIC; GraphConstants.setLineEnd(edge.getAttributes(), arrow);
    GraphConstants.setEndFill(edge.getAttributes(), true);
    graph.getGraphLayoutCache().insert(cells);
    JFrame frame = new JFrame();
    frame.getContentPane().add(new JScrollPane(graph));
    frame.pack();
    frame.setVisible(true);
    }
    }jsp页面
    <HTML><TITLE>HelloWorld! Applet</TITLE><APPLETcodebase="."CODE="hello.HelloWorld.class"name="HelloWorld" WIDTH=200HEIGHT=100ALIGN = middle> </APPLET></HTML>
      

  4.   

    applet不需要main方法,需要init等方法,自己找个applet的例子吧
      

  5.   

    做成静态图片,通过action或者servlet输出到页面就可以了
      

  6.   

    已经可以页面上显示了,用的静态图片方式,不能拖拽,代码在下方 。                                 我想做成一个可以拖拽布局的,就和它原来桌面程序一样,不知道使用applet能否实现此功能。BufferedImage img = graph.getImage(graph.getBackground(), 1);
    OutputStream  os = response.getOutputStream();
    if (img != null) {
        try {
    ImageIO.write(img, "JPEG", os);
    os.flush();

    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    os.close();
    }
    }
      

  7.   

    按说进将桌面程序里的jgraph图像代码搬到applet中去就可以了,记得指定jgraph的jar包
      

  8.   

    public class HelloWorld extends Applet { public void init() {
    GraphModel model = new DefaultGraphModel();
    GraphLayoutCache view = new GraphLayoutCache(model,
    new DefaultCellViewFactory());
    JGraph graph = new JGraph(model, view);
    DefaultGraphCell[] cells = new DefaultGraphCell[3];
    cells[0] = new DefaultGraphCell(new String("Hello"));
    GraphConstants.setBounds(cells[0].getAttributes(),
    new Rectangle2D.Double(20, 20, 40, 20));
    GraphConstants.setGradientColor(cells[0].getAttributes(), Color.orange);
    GraphConstants.setOpaque(cells[0].getAttributes(), true);
    DefaultPort port0 = new DefaultPort();
    cells[0].add(port0);
    cells[1] = new DefaultGraphCell(new String("World"));
    GraphConstants.setBounds(cells[1].getAttributes(),
    new Rectangle2D.Double(140, 140, 40, 20));
    GraphConstants.setGradientColor(cells[1].getAttributes(), Color.red);
    GraphConstants.setOpaque(cells[1].getAttributes(), true);
    DefaultPort port1 = new DefaultPort();
    cells[1].add(port1);
    DefaultEdge edge = new DefaultEdge();
    edge.setSource(cells[0].getChildAt(0));
    edge.setTarget(cells[1].getChildAt(0));
    cells[2] = edge;
    int arrow = GraphConstants.ARROW_CLASSIC;
    GraphConstants.setLineEnd(edge.getAttributes(), arrow);
    GraphConstants.setEndFill(edge.getAttributes(), true); graph.getGraphLayoutCache().insert(cells);
    JFrame frame = new JFrame();
    frame.getContentPane().add(new JScrollPane(graph));
    frame.pack();
    frame.setVisible(true);
    }
        
    }
    页面:<html>
      <head>  
      </head>
      <body>  
        <applet codebase="." 
                archive="jgraph.jar" 
                code="hello.HelloWorld.class" 
                name="HelloWorld" 
                width="320" 
                height="240">   
        </applet>
      </body>
    </html>
    访问页面时 ,流程图还是在跳出的窗口中显示,请各位高手帮助一下。怎么嵌入到页面中,而且在页面中也能拖拽啊?
      

  9.   

    public class HelloWorld extends Applet {
    public HelloWorld(){
    GraphModel model = new DefaultGraphModel();
    GraphLayoutCache view = new GraphLayoutCache(model,
    new DefaultCellViewFactory());
    JGraph graph = new JGraph(model, view);
    DefaultGraphCell[] cells = new DefaultGraphCell[3];
    cells[0] = new DefaultGraphCell(new String("Hello"));
    GraphConstants.setBounds(cells[0].getAttributes(),
    new Rectangle2D.Double(20, 20, 40, 20));
    GraphConstants.setGradientColor(cells[0].getAttributes(), Color.orange);
    GraphConstants.setOpaque(cells[0].getAttributes(), true);
    DefaultPort port0 = new DefaultPort();
    cells[0].add(port0);
    cells[1] = new DefaultGraphCell(new String("World"));
    GraphConstants.setBounds(cells[1].getAttributes(),
    new Rectangle2D.Double(140, 140, 40, 20));
    GraphConstants.setGradientColor(cells[1].getAttributes(), Color.red);
    GraphConstants.setOpaque(cells[1].getAttributes(), true);
    DefaultPort port1 = new DefaultPort();
    cells[1].add(port1);
    DefaultEdge edge = new DefaultEdge();
    edge.setSource(cells[0].getChildAt(0));
    edge.setTarget(cells[1].getChildAt(0));
    cells[2] = edge;
    int arrow = GraphConstants.ARROW_CLASSIC;
    GraphConstants.setLineEnd(edge.getAttributes(), arrow);
    GraphConstants.setEndFill(edge.getAttributes(), true); graph.getGraphLayoutCache().insert(cells);
    Panel panel = new Panel();
    panel.setSize(800000000, 60000000);
    panel.add(new JScrollPane(graph));
    this.add(panel);
    }用此方法已解决
      

  10.   

    怎么解决的啊,我也在学这个,。jgraph画拓扑图在页面显示,页面用applet做,像客户端,有数据库连接,可以拖拽改变拓扑图保存到数据库。有谁做个这样的例子啊。
      

  11.   

    flowGraph,很简单的生成流程图,可以看看
    https://sourceforge.net/p/flowgraph