[英]How can I change the UI of all components of a certain type?
How can I set the UI for all components in my application without having to reference each one of them using component.setUI(...);
如何在我的应用程序中为所有组件设置UI,而不必使用component.setUI(...);
引用每个component.setUI(...);
? ?
For example, I have several custom JScrollbars
throughout my program, 例如,我在整个程序中有几个自定义JScrollbars
,
and when you switch to another theme I have to reset all the UI's like this: scrollPane.getVerticalScrollBar().setUI(new CustomScrollBarUI());
当您切换到另一个主题时,我必须像这样重置所有UI: scrollPane.getVerticalScrollBar().setUI(new CustomScrollBarUI());
I would prefer to not have to look up each one seperately when changing themes. 更改主题时,我希望不必分别查找每个主题。 Is there a way to do this? 有没有办法做到这一点?
You can change the UIDefaults
early in your program: 您可以在程序的早期更改UIDefaults
:
UIDefaults uiDefaults = UIManager.getDefaults();
uiDefaults.put("ScrollBarUI", new CustomScrollBarUI());
See also Changing UI Default Settings in Java: The UIDefaults Class . 另请参见更改Java中的UI默认设置:UIDefaults类 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.