ERLEDIGT
JA
JA
ANTWORTEN
2
2
ZUGRIFFE
6852
6852
EMPFEHLEN
-
21.08.07 11:09 #1fscomputer Tutorials.de Gastzugang
Hallo zusammen!
ich möchte aus einer textdatei einen graphen erstellen.
hierzu möchte ich jgraph nutzen.
nun scheiter ich leider schon am erstellen des graphen, da es leider kein vernünftiges tutorial oder howto gibt.
ich habe einen beispielgraphen, den ich nun erstmal abwandeln möchte um jgraph und die arbeitsweise zu verstehen. leider bekomme ich sobald ich einen der zellwerte änder ne fehlermeldung...
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
import java.awt.Color; import java.awt.geom.Rectangle2D; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JScrollPane; import org.jgraph.JGraph; import org.jgraph.graph.DefaultEdge; import org.jgraph.graph.DefaultGraphCell; import org.jgraph.graph.DefaultGraphModel; import org.jgraph.graph.DefaultPort; import org.jgraph.graph.GraphConstants; import org.jgraph.graph.GraphModel; public class HelloWorld { public static void main(String[] args) { // Construct Model and Graph GraphModel model = new DefaultGraphModel(); JGraph graph = new JGraph(model); // Control-drag should clone selection graph.setCloneable(true); // Enable edit without final RETURN keystroke graph.setInvokesStopCellEditing(true); // When over a cell, jump to its default port (we only // have one, anyway) graph.setJumpToDefaultPort(true); // Insert all three cells in one call, so we need an // array to store them DefaultGraphCell[] cells = new DefaultGraphCell[3]; // Create Hello Vertex cells[0] = createVertex("Hello", 20, 20, 40, 20, null, false); // Create World Vertex cells[1] = createVertex("World", 200, 200, 40, 20, Color.ORANGE, true); // Create Edge DefaultEdge edge = new DefaultEdge(); // Fetch the ports from the new vertices, // and connect them with the edge edge.setSource(cells[0].getChildAt(0)); edge.setTarget(cells[1].getChildAt(0)); cells[2] = edge; // Set Arrow Style for edge int arrow = GraphConstants.ARROW_CLASSIC; GraphConstants.setLineEnd(edge.getAttributes(), arrow); GraphConstants.setEndFill(edge.getAttributes(), true); // Insert the cells via the cache, so they get selected graph.getGraphLayoutCache().insert(cells); // Show in Frame JFrame frame = new JFrame(); frame.getContentPane().add(new JScrollPane(graph)); //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } public static DefaultGraphCell createVertex(String name, double x, double y, double w, double h, Color bg, boolean raised) { // Create vertex with the given name DefaultGraphCell cell = new DefaultGraphCell(name); // Set bounds GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(x, y, w, h)); // Set fill color if (bg != null) { GraphConstants.setGradientColor( cell.getAttributes(), Color.orange); GraphConstants.setOpaque( cell.getAttributes(), true); } // Set raised border if (raised) GraphConstants.setBorder( cell.getAttributes(), BorderFactory.createRaisedBevelBorder()); else // Set black border GraphConstants.setBorderColor( cell.getAttributes(), Color.black); // Add a Port DefaultPort port = new DefaultPort(); cell.add(port); port.setParent(cell); return cell; } }
wenn ich eine zelle hinzufüge wird diese nicht angezeigt und wenn ich die arrays änder erscheint immer eine index oder out of bounds exception.
ich hoffe ihr könnt mir weiterhelfen!
danke schonmal.Geändert von fscomputer (21.08.07 um 11:12 Uhr)
-
21.08.07 11:49 #2fscomputer Tutorials.de Gastzugang
...alles klar hat sich erledigt... die Kanten de graphen zählen auch als element des arrays...
aber wenn jemand noch irgendwelche guides oder ähnlihces hat wär ich sehr dankbar!
-
Hallo,
hat jemand tipps, wie ich aus einer Textdatei einen Graphen erstelle...
Vielen Dank im Voraus
Ähnliche Themen
-
JGraph Kante mit JComboBox
Von mäcjava im Forum JavaAntworten: 1Letzter Beitrag: 03.01.11, 00:49 -
Zwei JPanel und jgraph
Von mäcjava im Forum JavaAntworten: 5Letzter Beitrag: 30.12.10, 15:42 -
JGraph
Von Matthias_Mac im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 2Letzter Beitrag: 25.08.09, 13:43 -
Streifen und Wellen - Graph in After Effects erstellen
Von Jatoll im Forum Videoschnitt, Videotechnik & -produktionAntworten: 1Letzter Beitrag: 06.05.09, 20:15 -
Einfaches Diagramm / Graph / Koordinatensystem aus Datei erstellen
Von Duke43 im Forum Visual Basic 6.0Antworten: 1Letzter Beitrag: 31.03.08, 07:54





Zitieren
Login





