使用 SWING + 时没有内容JUNG 刷新图形可视化
我的线程类中有以下 java 代码:
@Override
public void run() {
JFrame window = new JFrame("Visualization POC");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
while (true) {
window.setVisible(false);
Layout<Node,Edge> layout = new CircleLayout<Node, Edge>(graph);
layout.setSize(new Dimension(300, 300));
BasicVisualizationServer<Node, Edge> vv = new BasicVisualizationServer<Node, Edge>(layout);
vv.setPreferredSize(new Dimension(350, 350));
vv.getRenderContext().setVertexFillPaintTransformer(new NodeColorTransformer());
vv.getRenderContext().setEdgeDrawPaintTransformer(new EdgeColorTransformer());
window.getContentPane().add(vv);
window.pack();
window.setVisible(true);
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
我想用它来刷新图形可视化的状态,但我陷入了巨大的问题。当创建 JFrame 布局和设置内容的代码块位于 while 循环内时,它不会显示在输出窗口中。当我之前将其放置时,它工作正常,但这不是我想要的。我通过主类中的 SpringUtilities.invokeLater 运行此线程。
我可以看到窗口正在刷新,因为它闪烁了一段时间。 我期待任何提示。
I have following java code in my thread class:
@Override
public void run() {
JFrame window = new JFrame("Visualization POC");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
while (true) {
window.setVisible(false);
Layout<Node,Edge> layout = new CircleLayout<Node, Edge>(graph);
layout.setSize(new Dimension(300, 300));
BasicVisualizationServer<Node, Edge> vv = new BasicVisualizationServer<Node, Edge>(layout);
vv.setPreferredSize(new Dimension(350, 350));
vv.getRenderContext().setVertexFillPaintTransformer(new NodeColorTransformer());
vv.getRenderContext().setEdgeDrawPaintTransformer(new EdgeColorTransformer());
window.getContentPane().add(vv);
window.pack();
window.setVisible(true);
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
I want to use it to refresh state of graph visualization, but I got stuck on massive problem. When the block of code creating layout and setting content of JFrame is inside while loop it is not displayed in output window. When I place it before while, it works fine but it isn't that what I want. I run this thread via SpringUtilities.invokeLater in my main class.
I can see that the window is refresh, because it is blinking for a while.
I'm looking forward for any tips.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您从 EDT 线程调用代码。对组件的任何更新都将在 EDT 线程的末尾绘制。你的线程不会退出
我对你的代码做了一点修改,它工作得很好。请将 JLabel 替换为您的 jung 。
最终随机运行=新随机();
});
尝试 {
}
}
You invoke your code from EDT thread. Any update to the component will be painted at the end of the EDT thread. Your thread will not exit
I have modified your code little, it works fine. please replace JLabel with your jung .
final Random ran = new Random();
});
try {
}
}