gpt4 book ai didi

java - jframe 内的 Graphstream 小

转载 作者:行者123 更新时间:2023-12-01 10:00:56 24 4
gpt4 key购买 nike

我正在尝试更改图流内的图的大小,但它失败并且变得更小。

这是我的代码。起初,我无法设置窗口标题,因此我唯一的选择是创建一个 JFRAMe 并将 View 嵌入其中。因此,如果有一个选项可以设置图表的标题,我将不胜感激。

这是我的代码。

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);
}
}

@编辑

即使应用了建议的更改,也没有奏效。

public Clicks() 抛出 InterruptedException { System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); //我们像往常一样显示图表。这 //将图形输出连接到查看器。 //查看器是图的接收器。 Graph graph = new MultiGraph("点击次数"); graph.addAttribute("ui.stylesheet", "node#D{ fill-color:red; }node{ 描边模式: plain;size:20;text-size:30;描边颜色:#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
}

}

当我运行它时,窗口尺寸很小,我必须手动调整它的大小。

有什么问题吗?

最佳答案

When i run it, the window size is small, i have to manually resize it.

frame.pack();
frame.setVisible(true);

ViewerPipe fromViewer = viewer.newViewerPipe();
fromViewer.addViewerListener(this);
fromViewer.addSink(graph);

在使框架可见之前,您需要将所有组件添加到框架中。

所以代码应该是:

ViewerPipe fromViewer = viewer.newViewerPipe();
fromViewer.addViewerListener(this);
fromViewer.addSink(graph);

frame.pack();
frame.setVisible(true);

此外,也不需要以下行:

//frame.setSize(1000, 1000);

pack() 方法将根据添加的所有组件的首选大小重置大小。

关于java - jframe 内的 Graphstream 小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36812472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com