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?
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.