在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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:13:11  来源:igfitidea点击:

Drawing graphs on java

javagraphdrawingnodes

提问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 Dan Hamlin

JGraphTand JGraphare another option. JGraph is used for rendering graphs in the GUI and handling user interaction while JGraphT is the underlying graph model, data structures and algorithms.

JGraphTJGraph是另一种选择。JGraph 用于在 GUI 中渲染图形并处理用户交互,而 JGraphT 是底层图形模型、数据结构和算法。

回答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.

有很多选择。GVSR 项目维护一个列表。您只能将搜索限制为Java 库