0

我尝试通过 Graphstream 在 java 中构造图形。我想要两种类型的节点,形状默认为圆形或框。因此将类分配给节点。代码:

 System.setProperty("org.graphstream.ui.renderer","org.graphstream.ui.j2dviewer.J2DGraphRenderer");
 Graph g1= new  MultiGraph("db");
 g1.addAttribute("ui.stylesheet", "ui.label"," node.att{shape:box;}");
 Node n1 = g1.addNode("a");
 n1.setAttribute("ui.class","att");
 g1.display();

但在显示中,节点不是框,而是在输出中带有此消息的圆圈:

“ 样式表规范出错 '[Ljava.lang.Object;@192b996' 怎么办?”

我哪里错了?谢谢你的帮助。

4

1 回答 1

1
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.graphstream.graph.*;
import org.graphstream.graph.implementations.*;
import org.graphstream.ui.spriteManager.Sprite;
import org.graphstream.ui.spriteManager.SpriteManager;
import org.graphstream.ui.swingViewer.View;
import org.graphstream.ui.swingViewer.Viewer;

public class Main {
    /**
     * @param args
     */
    public static void main(String[] args) {
        Graph graph = new MultiGraph("graph");

        String styleSheet="node {"+
   " fill-color: grey;"+
   " size: 10px;"+
   " stroke-mode: plain;"+
   " stroke-color: black;"+
   " stroke-width: 1px;"+
   "}"+
   "node.important {"+
   " fill-color: red;"+
   " size: 30px;"+
   "}";

        graph.addNode("A");
        graph.addNode("B");
        graph.addEdge("AB", "A", "B");
        Node e1=graph.getNode("A");
        graph.addAttribute("ui.stylesheet", styleSheet);

        e1.addAttribute("ui.class", "important"); 
        e1.addAttribute("ui.label", "A Node");
        //e1.addAttribute( "ui.hide" );

        graph.display();
    }

}
于 2014-01-17T23:41:43.873 回答