简体   繁体   English

如何在JGraphX中将组件背景设置为特定颜色?

[英]How do I set the component background to a specific color in JGraphX?

I want to make the background of a JGraphX graph component ( https://github.com/jgraph/jgraphx ) a specific color all over. 我想让JGraphX图形组件( https://github.com/jgraph/jgraphx )的背景成为一种特定的颜色。 I tried the standard call for any Swing component: 我尝试了任何Swing组件的标准调用:

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: 由于mxGraphComponent扩展了JScrollPane更改了视图端口的背景:

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

From JScrollPane docs: 来自JScrollPane文档:

This can be accomplished by setting the background color of the viewport, via scrollPane.getViewport().setBackground(). 这可以通过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. 设置视口颜色而不是滚动窗格的原因是默认情况下JViewport是不透明的,除其他外,它意味着它将使用其背景颜色完全填充其背景。 Therefore when JScrollPane draws its background the viewport will usually draw over it. 因此,当JScrollPane绘制其背景时,视口通常会绘制它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM