javax.swing.plaf

接口
所有已知实现类:
ActionMapUIResource, BasicBorders.ButtonBorder, BasicBorders.FieldBorder, BasicBorders.MarginBorder, BasicBorders.MenuBarBorder, BasicBorders.RadioButtonBorder, BasicBorders.RolloverButtonBorder, BasicBorders.SplitPaneBorder, BasicBorders.ToggleButtonBorder, BasicComboBoxEditor.UIResource, BasicComboBoxRenderer.UIResource, BasicTextUI.BasicCaret, BasicTextUI.BasicHighlighter, BorderUIResource, BorderUIResource.BevelBorderUIResource, BorderUIResource.CompoundBorderUIResource, BorderUIResource.EmptyBorderUIResource, BorderUIResource.EtchedBorderUIResource, BorderUIResource.LineBorderUIResource, BorderUIResource.MatteBorderUIResource, BorderUIResource.TitledBorderUIResource, ColorUIResource, ComponentInputMapUIResource, DefaultListCellRenderer.UIResource, DefaultMenuLayout, DefaultTableCellRenderer.UIResource, DimensionUIResource, FontUIResource, IconUIResource, InputMapUIResource, InsetsUIResource, JScrollPane.ScrollBar, MetalBorders.ButtonBorder, MetalBorders.Flush3DBorder, MetalBorders.InternalFrameBorder, MetalBorders.MenuBarBorder, MetalBorders.MenuItemBorder, MetalBorders.OptionDialogBorder, MetalBorders.PaletteBorder, MetalBorders.PopupMenuBorder, MetalBorders.RolloverButtonBorder, MetalBorders.ScrollPaneBorder, MetalBorders.TextFieldBorder, MetalBorders.ToggleButtonBorder, MetalBorders.ToolBarBorder, MetalCheckBoxIcon, MetalComboBoxEditor.UIResource, MetalIconFactory.PaletteCloseIcon, ScrollPaneLayout.UIResource

public interface UIResource

此接口用于标记由 ComponentUI 委托创建的对象。ComponentUI.installUI()ComponentUI.uninstallUI() 方法可以使用此接口确定属性值是否已经被重写。例如,JList cellRenderer 属性只在其初始值为 null 时由 BasicListUI.installUI() 初始化:

 if (list.getCellRenderer() == null) {
     list.setCellRenderer((ListCellRenderer)(UIManager.get("List.cellRenderer")));
 }
 
在执行 uninstallUI() 时,如果该属性的值是 UIResource 的一个实例,则将该属性重置为 null:
 if (list.getCellRenderer() instanceof UIResource) {
     list.setCellRenderer(null);
 }
此模式应用于除 java.awt.Component 属性 font、foreground 和 background 之外的所有属性。如果这些属性中有一个未被初始化,或者被显式设置为 null,则其容器将提供该值。因此,在调用 installUI() 来动态更新组件外观时, "== null" 是不可靠的。因此,在执行 installUI() 时,要检查当前值是否是一个 UIResource:
 if (!(list.getFont() instanceof UIResource)) {
     list.setFont(UIManager.getFont("List.font"));
 }
 

另请参见:
ComponentUI