The figure corresponding to the GEF's rooteditpart is a layeredpane composed of multiple layers. Each layer contains different types of graphic elements, such as nodes, connections, and grid lines. Therefore, to make the graphic editor display an image as the background, you can draw the image in one of the layers, or add a layer to place the background image. I recommend using the latter:CodeThe following is a simple modification made on the basis of the previous gefpractice project:
Static Image bg_image = New Image ( Null , " C: \ bg.jpg " );
Protected Void Configuregraphicalviewer (){
Super . Configuregraphicalviewer ();
Getgraphicalviewer (). setrooteditpart ( New Scalablefreeformrooteditpart (){
// Override the createlayers method of scalablefreeformrooteditpart to add your own layer.
Protected Void Createlayers (layeredpane ){
Layer Layer = New Freeformlayer (){
Protected Void Paintfigure (Graphics graphics ){
Super . Paintfigure (graphics );
// Draw an image on the layer or draw other images as the background. The gridlines of GEF are an example.
Graphics. drawimage (bg_image, 0 , 0 );
}
};
Layeredpane. Add (layer );
Super . Createlayers (layeredpane );
}
});
Getgraphicalviewer (). seteditpartfactory ( New Partfactory ());
}
In this way, only the visible area of the editor is displayed, that is, the background image will scroll with the scroll bar. See.
Graphic editor with background image
Project download (the title of the background image is "C: \ bg.jpg ")