简体   繁体   English

如何更改特定类型的所有组件的UI?

[英]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.

相关问题 如何在java swing中为所有类型的组件设置UI? - How to set UI for all Components of a type in java swing? 如何更改组件之间的焦点 - How can I change focus between components 如何以编程方式动态创建所有Android ui组件的列表?例如TextView,ImageView等 - How can I dynamically create a list of all Android ui components programmatically? e.g. TextView, ImageView etc 如何将 MVVM 与 App/activity 和 AsyncTask 的 UI 组件一起使用 - How can I use MVVM with the UI components of the App/activity and AsyncTask 如何将动画添加到现有的UI组件? - How can i add animations to existing UI components? 如何使用Spring XML配置来设置包含特定类型的所有bean的列表的bean属性? - How can I use Spring XML configuration to set a bean property with list of all beans of a certain type? 更改Java中特定类型的所有对象的属性 - Change attributes of all objects of a certain type in Java 使用NetBeans UI设计器,如何从一个项目复制UI组件并将其粘贴到另一个项目中? - Using NetBeans UI designer, how can I copy UI components from one project and paste them into another? 如何获取Java Swing中一块面板的所有元件? - How can I get all the components of a panel in Java Swing? 如何只用一个事件听我的所有组件? - How can I listen my all components with only one event?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM