gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 02:26:54 24 4
gpt4 key购买 nike

我想使 JGraphX 图形组件 ( https://github.com/jgraph/jgraphx ) 的背景全部为特定颜色。我尝试了任何 Swing 组件的标准调用:

graphComponent.setBackground(Color.BLACK);

但这没有任何效果。我也尝试过强制重新绘制组件,但没有成功。调用不正确,还是有一些特定的方法来强制刷新?

最佳答案

由于 mxGraphComponent 扩展了 JScrollPane 更改了视口(viewport)的背景:

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

来自 JScrollPane文档:

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.

关于java - 如何在 JGraphX 中将组件背景设置为特定颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20357738/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com