Ich habe einige Manipulationen an Ihrem Code gemacht und das sollte funktionieren.
Der Teil, der Pfeile folgt Teil
// This part to remove arrow from edge
mxUtils.setCellStyles(graphComponent.getGraph().getModel(),
cells.toArray(), mxConstants.STYLE_ENDARROW, mxConstants.NONE);
So ist der vollständige Code wie dies wäre entfernt, und es ist nur ein Beispiel und der Rest Ihrer Fantasie überlassen:
import com.mxgraph.layout.mxCircleLayout;
import com.mxgraph.model.mxGraphModel;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxUtils;
import org.jgrapht.UndirectedGraph;
import org.jgrapht.ext.JGraphXAdapter;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.graph.SimpleGraph;
import javax.swing.*;
import java.awt.*;
import java.util.Collection;
public class UndirectedGraphClass extends JFrame {
public static void main(String[] args) {
new UndirectedGraphClass();
}
private UndirectedGraphClass() {
JGraphXAdapter<String, DefaultEdge> jgxAdapter;
UndirectedGraph<String, DefaultEdge> g =
new SimpleGraph<String, DefaultEdge>(DefaultEdge.class);
g.addVertex("a");
g.addVertex("b");
g.addEdge("a", "b");
jgxAdapter = new JGraphXAdapter<String, DefaultEdge>(g);
mxGraphComponent graphComponent = new mxGraphComponent(jgxAdapter);
mxGraphModel graphModel = (mxGraphModel) graphComponent.getGraph().getModel();
Collection<Object> cells = graphModel.getCells().values();
// This part to remove arrow from edge
mxUtils.setCellStyles(graphComponent.getGraph().getModel(),
cells.toArray(), mxConstants.STYLE_ENDARROW, mxConstants.NONE);
getContentPane().add(graphComponent);
mxCircleLayout layout = new mxCircleLayout(jgxAdapter);
layout.execute(jgxAdapter.getDefaultParent());
this.setTitle(" some undirected graph ");
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setPreferredSize(new Dimension(400, 400));
this.pack();
this.setVisible(true);
}
}
Die Lösung ist von dieser answer inspiriert.
Entschuldigung nur zu verstehen, was Sie erreichen wollen und was nicht funktioniert? –
Ich möchte in meinem Panel ungerichtete Grafik (Rand ohne einen Pfeil) zeigt –
Gibt es einen Grund zu * nicht * dies als ein Duplikat von https://stackoverflow.com/questions/26084742/undirected-graphs-in-jgraphx betrachten ? – Marco13