-1
我使用jung(java)嘗試繪製圓形到背景。我沒有得到任何輸出,並想知道爲什麼它不工作。Java Jung繪製橢圓
Iam使用PreRenderPaintable和PostRenderPaintable,但仍然沒有結果。
vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {
public void paint(Graphics g)
{
System.out.println("PRE RENDER");
System.out.println("vv.getComponentCount()= " + vv.getComponentCount());
Graphics2D g2d = (Graphics2D)g;
AffineTransform oldXform = g2d.getTransform();
AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).getTransform();
AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).getTransform();
AffineTransform at = new AffineTransform();
at.concatenate(g2d.getTransform());
at.concatenate(vat);
at.concatenate(lat);
g2d.setTransform(at);
g.drawOval(100, 100, 150, 150);
g.drawString("adsadd", 200, 200);
g2d.setTransform(oldXform);
}
public boolean useTransform() { return false; }
});
vv.addPostRenderPaintable(new VisualizationViewer.Paintable()
{
public void paint(Graphics g)
{
System.out.println("POST RENDER");
System.out.println("vv.getComponentCount()= " + vv.getComponentCount());
Component comp = vv.getComponent(0);
System.out.println(comp);
System.out.println(comp.getClass());
g.drawString("adasasdsadasdsadsadasdasdsadd", 300, 300);
}
public boolean useTransform()
{
return false;
}
});
你有沒有得到任何異常?如果是的話,請張貼堆棧跟蹤.. – AurA
我沒有得到任何例外。只有這樣的輸出:預渲染 vv.getComponentCount()= 1個 後期渲染 vv.getComponentCount()= 1 javax.swing.CellRendererPane [0 ,0,0x0,隱藏] class javax.swing.CellRendererPane – hehe