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

标签 java swing background jcomponent jgraphx

我想使 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/

相关文章:

java - 自定义 Swing 组件和更新 JScrollPane 滚动条

jquery - Bootstrap 页脚列堆叠和松散页脚颜色

javascript - 将音频切成背景音乐-PhoneGap应用

java - java中使用泛型的工厂方法模式,如何?

java - Firebase 更新后 RecyclerView 不刷新

java - 防止从退出按钮关闭 JDialog

ios - Xamarin.Forms iOS 无法自定义通知

带有 Android 客户端的 Java 游戏服务器

java - 如何在 Maven 中读取外部属性文件

java - 禁用时如何阻止 JButton 变灰?