作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试在 JGraphx 中显示图表。只要我使用有向图,一切都很好,但是当我尝试显示一个无向的时,它显示了有方向。
代码来自jgrapht的demo。
package org.jgrapht.demo;
import com.mxgraph.layout.*;
import com.mxgraph.swing.*;
import java.awt.*;
import java.nio.file.FileSystem;
import javax.swing.*;
import org.jgrapht.*;
import org.jgrapht.ext.*;
import org.jgrapht.graph.*;
/**
* A demo applet that shows how to use JGraphX to visualize JGraphT graphs.
* Applet based on JGraphAdapterDemo.
*
* @since July 9, 2013
*/
public class JGraphXAdapterDemo
extends JApplet
{
private static final long serialVersionUID = 2202072534703043194L;
private static final Dimension DEFAULT_SIZE = new Dimension(530, 320);
private JGraphXAdapter<String, DefaultEdge> jgxAdapter;
/**
* An alternative starting point for this demo, to also allow running this
* applet as an application.
*
* @param args ignored.
*/
public static void main(String [] args)
{
JGraphAdapterDemo applet = new JGraphAdapterDemo();
applet.init();
JFrame frame = new JFrame();
frame.getContentPane().add(applet);
frame.setTitle("JGraphT Adapter to JGraph Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
/**
* {@inheritDoc}
*/
public void init()
{
// create a JGraphT graph
ListenableUndirectedGraph<String, DefaultEdge> g =
new ListenableUndirectedGraph<String, DefaultEdge>(
DefaultEdge.class);
// create a visualization using JGraph, via an adapter
jgxAdapter = new JGraphXAdapter<String, DefaultEdge>(g);
getContentPane().add(new mxGraphComponent(jgxAdapter));
resize(DEFAULT_SIZE);
String v1 = "v1";
String v2 = "v2";
String v3 = "v3";
String v4 = "v4";
// add some sample data (graph manipulated via JGraphX)
g.addVertex(v1);
g.addVertex(v2);
g.addVertex(v3);
g.addVertex(v4);
g.addEdge(v1, v2);
g.addEdge(v2, v3);
g.addEdge(v3, v1);
g.addEdge(v4, v3);
// positioning via jgraphx layouts
mxCircleLayout layout = new mxCircleLayout(jgxAdapter);
layout.execute(jgxAdapter.getDefaultParent());
// that's all there is to it!...
}
}
是否可以无向显示?
谢谢
托尔本
PS:抱歉我的英语不好
最佳答案
您可以将mxGraphComponent
中的边缘样式设置为NONE
:
mxGraphComponent graphComponent = new mxGraphComponent(jgxAdapter);
mxGraphModel graphModel = (mxGraphModel)graphComponent.getGraph().getModel();
Collection<Object> cells = graphModel.getCells().values();
mxUtils.setCellStyles(graphComponent.getGraph().getModel(),
cells.toArray(), mxConstants.STYLE_ENDARROW, mxConstants.NONE);
//instead of getContentPane().add(new mxGraphComponent(jgxAdapter));
getContentPane().add(graphComponent);
关于java - JGraphX 中的无向图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26084742/
为了获得我的瓷砖,我这样做: style(styleUri = Style.MAPBOX_STREETS) { +vectorSource(id = "parcel-source") {
我是一名优秀的程序员,十分优秀!