0

I am working in my Java project and I am using GraphStream library to visually represent graphs. My question is how to put an image behind a graph? I want an image as a background to my graph.

rtruszk
  • 3,902
  • 13
  • 36
  • 53
user132226
  • 11
  • 1
  • 1

2 Answers2

2

The method setBackLayerRenderer() is implemented in the class DefaultView, here's what worked for me:

Graph graph = new SingleGraph("graph");`
Viewer viewer = graph.display();
DefaultView view = (DefaultView) viewer.getDefaultView();
view.setBackLayerRenderer(new LayerRenderer() {
    @Override
    public void render(Graphics2D graphics2D, GraphicGraph  graphicGraph, double v, int i, int i1, double v1, double v2, double v3, double v4) {
        graphics2D.setColor(Color.green);
        graphics2D.drawString("hello", 10, 30);
    }
});
acastele
  • 21
  • 5
0

I think this can be achieved using LayerRenderer interface with View.setBackLayerRenderer() / View.setFrontLayerRenderer() methods. You can find more here.

Raúl
  • 1,542
  • 4
  • 24
  • 37