Question

I want to make the background of a JGraphX graph component (https://github.com/jgraph/jgraphx) a specific color all over. I tried the standard call for any Swing component:

graphComponent.setBackground(Color.BLACK);

but this has no effect. I tried forcing a repaint of the component also, no luck. Is the call incorrect, or is there some specific way to force a refresh?

Was it helpful?

Solution

Since mxGraphComponent extends JScrollPane change the background of the view port:

graphComponent.getViewport().setOpaque(true);
graphComponent.getViewport().setBackground(Color.BLACK);

From JScrollPane docs:

This can be accomplished by setting the background color of the viewport, via scrollPane.getViewport().setBackground(). The reason for setting the color of the viewport and not the scrollpane is that by default JViewport is opaque which, among other things, means it will completely fill in its background using its background color. Therefore when JScrollPane draws its background the viewport will usually draw over it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top