问题描述
我发现了很多使用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属性的自定义设置,据记录 fi:
LAFs are free to ignore custom settings of some (visual only? don't know) JComponent properties, as documented f.i.:
因此,结果是高度依赖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的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!