如何在运行时更改JTabbedPane的背景颜色? [英] How to change background color of JTabbedPane in runtime?

查看:94
本文介绍了如何在运行时更改JTabbedPane的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了很多使用setBackgroundAt()UIManager.put("JTabbedPane...")

但是,我想在一个复选框上创建一个onclick事件,将其选中时将背景色更改为绿色,而取消选择时将其更改为默认值.

However, I want to create an onclick event on a checkbox that changes the background color to green when you select it, and back to default when you unselect it.

我无法使用上述方法进行这项工作.

I haven't been able to make that work using the above methods.

有什么想法吗?

PS:由于某些原因,我可以使用setForgroundAt()来更改前景色,但不能更改背景

PS: I can change the foreground color by using setForgroundAt() but not the background for some reason

推荐答案

LAF可以随意忽略某些(仅可见的?不知道的)JComponent属性的自定义设置,

LAFs are free to ignore custom settings of some (visual only? don't know) JComponent properties, as documented f.i.:

外观和感觉取决于该属性,有些人可能会选择忽略它.

It is up to the look and feel to honor this property, some may choose to ignore it.

因此,结果是高度依赖LAF的(Metal和Motif中的Worksforme,而不是Nimbus/Win中)没有简单,安全的方法(调整ui委托除外,这不是一个真正的选择)

So the outcome is highly LAF-dependent (Worksforme in Metal and Motif, not in Nimbus/Win) No easy and safe way around (except tweaking the ui delegate, which isn't a real option)

这篇关于如何在运行时更改JTabbedPane的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆