在java上绘制图形
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2981825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Drawing graphs on java
提问by nunos
I want to draw graphs (nodes and edges) in Java. However, since I don't know how to go about it, I would like to have some advice before starting.
我想用 Java 绘制图形(节点和边)。但是,由于我不知道该怎么做,所以我想在开始之前得到一些建议。
How should I do this?
我该怎么做?
use Graphics2D package, right?
使用 Graphics2D 包,对吗?
How about the labels for the nodes? should I use something like drawString and handle all the "centering" manually or create a JLabel for that? Can I put a JLabel on a Graphics2D environment?
节点的标签怎么样?我应该使用 drawString 之类的东西并手动处理所有“居中”还是为此创建一个 JLabel?我可以将 JLabel 放在 Graphics2D 环境中吗?
I have searched but haven't found any simple implementation of this. If you know of one, please provide the link in your answer.
我已经搜索过,但没有找到任何简单的实现。如果您知道其中之一,请在您的答案中提供链接。
edit: The solution I am looking for should be able to remove nodes, drag nodes, edit labels, create nodes, all with mouse events.
编辑:我正在寻找的解决方案应该能够删除节点、拖动节点、编辑标签、创建节点,所有这些都带有鼠标事件。
Thanks.
谢谢。
采纳答案by trashgod
"Graph Panelis a simple example of an object drawing program." More complex alternatives are cited here.
回答by nunos
Perhaps this will help: JUNG.
也许这会有所帮助:JUNG。
And you will probably need to read this: http://jung.sourceforge.net/doc/JUNGVisualizationGuide.html
您可能需要阅读以下内容:http: //jung.sourceforge.net/doc/JUNGVisualizationGuide.html
回答by svlada
I would suggest grappa. http://www.research.att.com/~john/Grappa/grappa.tgz
我会推荐格拉巴酒。http://www.research.att.com/~john/Grappa/grappa.tgz
回答by Dan Hamlin
回答by stacker
If you want to do it yourself the GraphLayout exampleswill help.
如果您想自己动手,GraphLayout 示例会有所帮助。
This is a good examplewith only a few lines of code.
If you want to use a more sophisticated framwork check JGraph
如果你想使用更复杂的框架检查JGraph
回答by Martin Harrigan
There are lots of choices. The GVSR Projectmaintains a list. You can limit your search to Java librariesonly.