B
bygones
Gast
da in diesem verf$%!@#$% JGraph forum der admin irgendwann mal einen freischaltet, stell ich hier mal meine frage in der hoffnung jemand kennt sich mit der lib aus
ich hab einen einfachen Graphen, der auch korrekt angezeigt wird (wenn ich in ein JFrame packe), doch unten beim speichern wird mir nur ein weisses leeres bild erstellt.
hat jemand eine ahnung was falsch hier ist ?
ich hab einen einfachen Graphen, der auch korrekt angezeigt wird (wenn ich in ein JFrame packe), doch unten beim speichern wird mir nur ein weisses leeres bild erstellt.
hat jemand eine ahnung was falsch hier ist ?
Code:
GraphModel model = new DefaultGraphModel();
GraphLayoutCache view = new GraphLayoutCache( model, new DefaultCellViewFactory() );
JGraph graph = new JGraph( model, view );
DefaultGraphCell[] cells = new DefaultGraphCell[ 3 ];
cells[ 0 ] = new DefaultGraphCell( new String( "Hello" ) );
GraphConstants.setBounds( cells[ 0 ].getAttributes(), new Rectangle2D.Double( 20, 20, 40, 20 ) );
GraphConstants.setGradientColor( cells[ 0 ].getAttributes(), Color.orange );
GraphConstants.setOpaque( cells[ 0 ].getAttributes(), true );
DefaultPort port0 = new DefaultPort();
cells[ 0 ].add( port0 );
cells[ 1 ] = new DefaultGraphCell( new String( "World" ) );
GraphConstants.setBounds( cells[ 1 ].getAttributes(), new Rectangle2D.Double( 140, 140, 40, 20 ) );
GraphConstants.setGradientColor( cells[ 1 ].getAttributes(), Color.red );
GraphConstants.setOpaque( cells[ 1 ].getAttributes(), true );
DefaultPort port1 = new DefaultPort();
cells[ 1 ].add( port1 );
DefaultEdge edge = new DefaultEdge();
edge.setSource( cells[ 0 ].getChildAt( 0 ) );
edge.setTarget( cells[ 1 ].getChildAt( 0 ) );
cells[ 2 ] = edge;
int arrow = GraphConstants.ARROW_CLASSIC;
GraphConstants.setLineEnd( edge.getAttributes(), arrow );
GraphConstants.setEndFill( edge.getAttributes(), true );
graph.getGraphLayoutCache().insert( cells );
BufferedImage img = graph.getImage(graph.getBackground(), 5);
ImageIO.write(img, "jpg", new File("test.jpg"));