我正在使用jung(java)尝试将圆圈绘制到背景中。我没有得到任何输出,并想知道它为什么不起作用。
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;
}
});
答案 0 :(得分:0)
问题是没有设置输出的颜色。 例如:
g.setFont(font);
Color oldColor = g.getColor();
g.setColor(Color.lightGray);