Skip to content

Instantly share code, notes, and snippets.

@kishida
Last active April 8, 2023 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kishida/14b2041a25a0ae64260899b64374dc95 to your computer and use it in GitHub Desktop.
Save kishida/14b2041a25a0ae64260899b64374dc95 to your computer and use it in GitHub Desktop.
JGraphXのサンプル
package neoki.slm;
import javax.swing.*;
import java.awt.*;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
public class JGraphXExample {
public static void main(String[] args) {
JFrame frame = new JFrame("JGraphX Example");
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try {
Object vertex1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80, 30);
Object vertex2 = graph.insertVertex(parent, null, "World!", 240, 150, 80, 30);
graph.insertEdge(parent, null, "Edge", vertex1, vertex2);
} finally {
graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
frame.getContentPane().add(graphComponent);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 320);
frame.setVisible(true);
}
}
<!DOCTYPE html>
<html>
<head>
<title>mxGraph JavaScript Example</title>
<script type="text/javascript" src="https://unpkg.com/mxgraph@4.2.2/javascript/mxClient.js"></script>
</head>
<body>
<div id="graphContainer" style="width: 100%; height: 100%;"></div>
<script type="text/javascript">
function main(container) {
if (!mxClient.isBrowserSupported()) {
mxUtils.error('Browser is not supported!', 200, false);
} else {
var graph = new mxGraph(container);
var parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try {
var vertex1 = graph.insertVertex(parent, null, 'Hello', 20, 20, 80, 30);
var vertex2 = graph.insertVertex(parent, null, 'World!', 240, 150, 80, 30);
graph.insertEdge(parent, null, 'Edge', vertex1, vertex2);
} finally {
graph.getModel().endUpdate();
}
}
}
main(document.getElementById('graphContainer'));
</script>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>naoki</groupId>
<artifactId>SmallLanguageModel</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.github.vlsi.mxgraph</groupId>
<artifactId>jgraphx</artifactId>
<version>4.2.2</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment