JavaTM 2 Platform
Standard Ed. 6

javax.swing.plaf
介面 UIResource

所有已知實作類別:
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


JavaTM 2 Platform
Standard Ed. 6

提交錯誤或意見

版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only