Created
September 27, 2016 19:22
-
-
Save insac/e56cb6cc5449acad1c0a70cee6f68531 to your computer and use it in GitHub Desktop.
An example of a multi-value node in JGraphX using "child nodes"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.JFrame; | |
import com.mxgraph.layout.mxGraphLayout; | |
import com.mxgraph.model.mxCell; | |
import com.mxgraph.model.mxGeometry; | |
import com.mxgraph.model.mxICell; | |
import com.mxgraph.swing.mxGraphComponent; | |
import com.mxgraph.view.mxGraph; | |
public class Example extends JFrame { | |
mxGraph graph=null; | |
mxGraphLayout layout=null; | |
public static void main(String[] args) { | |
Example frame = new Example(); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.setSize(400, 320); | |
frame.setVisible(true); | |
} | |
public Example() { | |
graph = new mxGraph() { | |
public boolean isCellFoldable(Object cell, boolean collapse) | |
{ | |
return false; | |
} | |
public boolean isCellSelectable(Object cell) { | |
return !model.isEdge(cell); | |
} | |
}; | |
Object parent = graph.getDefaultParent(); | |
graph.getModel().beginUpdate(); | |
try | |
{ | |
mxICell containerNode=(mxICell)graph.insertVertex(parent, null, "", 10, 10, 100, 100, ""); | |
mxICell sampleNode=(mxICell)graph.insertVertex(parent, null, "Sample", 200, 10, 100, 100, ""); | |
graph.insertEdge(parent, null, null, containerNode, sampleNode); | |
mxGeometry geo = new mxGeometry(0.0, 0.1, 100, 65); | |
geo.setRelative(true); | |
mxCell titleCell = new mxCell("Title", geo,""); | |
titleCell.setVertex(true); | |
mxGeometry geo1 = new mxGeometry(0.0, 0.75, 50, 25); | |
geo1.setRelative(true); | |
mxCell labelCell = new mxCell("Label", geo1,""); | |
labelCell.setVertex(true); | |
mxGeometry geo2 = new mxGeometry(0.5, 0.75, 50, 25); | |
geo2.setRelative(true); | |
mxCell valueCell = new mxCell("Value", geo2,""); | |
valueCell.setVertex(true); | |
graph.addCell(titleCell, containerNode); | |
graph.addCell(labelCell, containerNode); | |
graph.addCell(valueCell, containerNode); | |
} | |
finally | |
{ | |
graph.getModel().endUpdate(); | |
} | |
mxGraphComponent graphComponent = new mxGraphComponent(graph); | |
getContentPane().add(graphComponent); | |
graphComponent.doLayout(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment