我尝试通过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'?”
我哪里错了? 谢谢你的帮助。
答案 0 :(得分: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();
}
}