我正在尝试更改图形流内的图形的大小,但它失败并且变得更小。
这是我的代码。起初,我无法设置窗口标题,所以我唯一的选择是创建一个 JFRAMe 并将视图嵌入其中。所以,如果有一个选项来设置图表的标题,我将不胜感激。
这是我的代码。
public class Clicks implements ViewerListener {
protected boolean loop = true;
public static void main(String args[]) throws InterruptedException {
new Clicks();
}
public Clicks() throws InterruptedException {
System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
// We do as usual to display a graph. This
// connect the graph outputs to the viewer.
// The viewer is a sink of the graph.
Graph graph = new MultiGraph("Clicks");
graph.addAttribute("ui.stylesheet", "node#D{ fill-color:red; }node{ stroke-mode: plain;size:20;text-size:30;stroke-color:#333333;text-background-color:#FFF;text-background-mode:plain;text-alignment:above;}");
Node D = graph.addNode("D");
Node J = graph.addNode("J");
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
View view = viewer.addDefaultView(false);
JFrame frame = new JFrame("title");
frame.setSize(1000, 1000);
frame.add((Component) view);
frame.pack();
frame.setVisible(true);
ViewerPipe fromViewer = viewer.newViewerPipe();
fromViewer.addViewerListener(this);
fromViewer.addSink(graph);
while(loop) {
fromViewer.blockingPump();// or fromViewer.blockingPump(); in the nightly builds
}
}
public void viewClosed(String id) {
loop = false;
}
public void buttonPushed(String id) {
}
public void buttonReleased(String id) {
System.out.println("Button released on node "+id);
}
}
@编辑
即使应用了提议的更改,它也不起作用。
公共 Clicks() 抛出 InterruptedException { System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); // 我们照常显示图表。这 // 将图形输出连接到查看器。// 查看器是图的接收器。Graph graph = new MultiGraph("Clicks"); graph.addAttribute("ui.stylesheet", "node#D{ fill-color:red; }node{ stroke-mode: plain;size:20;text-size:30;stroke-color:#333333;text-background -颜色:#FFF;文本背景模式:纯色;文本对齐:以上;}");
Node D = graph.addNode("D");
Node J = graph.addNode("J");
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
View view = viewer.addDefaultView(false);
JFrame frame = new JFrame("title");
frame.add((Component) view);
ViewerPipe fromViewer = viewer.newViewerPipe();
fromViewer.addViewerListener(this);
fromViewer.addSink(graph);
frame.pack();
frame.setVisible(true);
while(loop) {
fromViewer.blockingPump();// or fromViewer.blockingPump(); in the nightly builds
}
}
当我运行它时,窗口大小很小,我必须手动调整它的大小。
有什么问题?