模块 java.desktop

类 BasicLookAndFeel

java.lang.Object
javax.swing.LookAndFeel
javax.swing.plaf.basic.BasicLookAndFeel
所有已实现的接口:
Serializable
已知子类:
MetalLookAndFeel , SynthLookAndFeel

public abstract class BasicLookAndFeel extends LookAndFeel implements Serializable
用于为 Swing 创建外观的基类。

BasicLookAndFeel 提供的每个 ComponentUI 都从默认表派生其行为。除非另有说明,否则此包中的每个 ComponentUI 实现都记录了它们使用的默认值集。除非另有说明,否则会在调用 installUI 时安装默认值,并按照 LookAndFeel 中概述的建议安装默认值。

Warning: 此类的序列化对象将与未来的 Swing 版本不兼容。当前的序列化支持适用于运行相同版本 Swing 的应用程序之间的短期存储或 RMI。从 1.4 开始,对所有 JavaBeans 的长期存储的支持已添加到 java.beans 包中。请参阅 XMLEncoder

  • 构造方法详细信息

    • BasicLookAndFeel

      protected BasicLookAndFeel()
      子类调用的构造方法。
  • 方法详情

    • getDefaults

      public UIDefaults  getDefaults()
      返回外观默认值。返回的 UIDefaults 通过依次调用 initClassDefaultsinitSystemColorDefaultsinitComponentDefaults 来填充。

      虽然此方法是公共的,但只有当外观设置为当前外观时以及调用 initialize 后,它才应由 UIManager 调用。

      重写:
      getDefaults 在类 LookAndFeel
      返回:
      外观默认
      参见:
    • initClassDefaults

      protected void initClassDefaults(UIDefaults  table)
      使用从 uiClassID 到 ui 类的完全限定名称的映射填充 table。特定 uiClassID 的值为 "javax.swing.plaf.basic.Basic + uiClassID" 。例如,uiClassID TreeUI 的值为 "javax.swing.plaf.basic.BasicTreeUI"
      参数:
      table - 条目添加到的 UIDefaults 实例
      抛出:
      NullPointerException - 如果 tablenull
      参见:
    • initSystemColorDefaults

      protected void initSystemColorDefaults(UIDefaults  table)
      使用系统颜色填充 table。这将创建一个 name-color 对数组并调用 loadSystemColors

      该名称是一个 String,对应于 SystemColor 类中的静态 SystemColor 字段之一的名称。为每个这样的 SystemColor 字段创建名称-颜色对。

      color 对应于 Color.decode 理解的十六进制 String。例如,name-color 对之一是 "desktop"-"#005C5C"。这对应于 SystemColor 字段 desktop,颜色值为 new Color(0x005C5C)

      下面显示了两个 name-color 对:

        String[] nameColorPairs = new String[] {
           "desktop", "#005C5C",
        "activeCaption", "#000080" };
        loadSystemColors(table, nameColorPairs, isNativeLookAndFeel());
       
      如前所述,这会使用提供的 tablename-color 对数组调用 loadSystemColorsloadSystemColors 的最后一个参数指示是否应使用 SystemColor 中的字段值。此方法将 isNativeLookAndFeel() 的值作为最后一个参数传递给 loadSystemColors
      参数:
      table - 将值添加到的 UIDefaults 对象
      抛出:
      NullPointerException - 如果 tablenull
      参见:
    • loadSystemColors

      protected void loadSystemColors(UIDefaults  table, String [] systemColors, boolean useNative)
      systemColors 中的 name-color 对填充 table。有关 systemColors 格式的详细信息,请参阅 initSystemColorDefaults(UIDefaults)

      systemColors 中的每个 name-color 对添加一个条目到 table。输入密钥是 name-color 对中的 name

      条目的值对应于 name-color 对中的 color。条目的值以两种方式之一计算。无论哪种方法,该值始终是 ColorUIResource

      如果 useNativefalse,则通过使用 Color.decode String 转换为 Color 创建 color。如果 decode 无法将 String 转换为 Color(抛出 NumberFormatException),则使用黑色的 ColorUIResource

      如果 useNativetrue,则 colorSystemColor 中与 name-color 对的 name 同名的字段的值。如果该字段无效,则使用黑色的 ColorUIResource

      参数:
      table - 将值添加到的 UIDefaults 对象
      systemColors - name-color 对的数组,如 initSystemColorDefaults(UIDefaults) 中所述
      useNative - 颜色是否从 SystemColorColor.decode 获得
      抛出:
      NullPointerException - 如果 systemColorsnull ;或者 systemColors 不为空,而 tablenull ;或者 name-color 对的名称之一是 null ;或者 useNativefalsename-color 对中的 colors 之一是 null
      ArrayIndexOutOfBoundsException - 如果 useNativefalse 并且 systemColors.length 是奇数
      参见:
    • initComponentDefaults

      protected void initComponentDefaults(UIDefaults  table)
      使用基本外观的默认值填充 table
      参数:
      table - 要将值添加到的 UIDefaults
      抛出:
      NullPointerException - 如果 tablenull
    • getAudioActionMap

      protected ActionMap  getAudioActionMap()
      返回包含此外观的音频操作的 ActionMap

      返回的 ActionMap 包含 Actions,体现了呈现听觉提示的能力。这些听觉提示映射到可能对最终用户了解有用的用户和系统活动(例如出现的对话框)。

      在适当的时候,ComponentUI 负责从 ActionMap 中获取一个 Action 并将其传递给 playSound

      此方法首先使用键 "AuditoryCues.actionMap" 从默认值中查找 ActionMap

      如果值为 non-null ,则返回。如果默认值 "AuditoryCues.actionMap"null,默认值 "AuditoryCues.cueList"non-null,则创建并填充 ActionMapUIResource。填充是通过迭代 "AuditoryCues.cueList" 数组的每个元素并调用 createAudioAction() 为每个元素创建一个 Action 来完成的。生成的 Action 放置在 ActionMapUIResource 中,使用数组元素作为键。例如,如果 "AuditoryCues.cueList" 数组包含单个元素 "audioKey" ,则会创建 ActionMapUIResource,然后通过 actionMap.put(cueList[0], createAudioAction(cueList[0])) 进行填充。

      如果默认 "AuditoryCues.actionMap" 的值为 null 并且默认 "AuditoryCues.cueList" 的值为 null ,则会创建一个空的 ActionMapUIResource

      返回:
      包含 Actions 的 ActionMap 负责播放听觉提示
      抛出:
      ClassCastException - 如果默认值 "AuditoryCues.actionMap" 不是 ActionMap,或者默认值 "AuditoryCues.cueList" 不是 Object[]
      自从:
      1.4
      参见:
    • createAudioAction

      protected Action  createAudioAction(Object  key)
      创建并返回用于播放声音的 Action

      如果 keynon-null ,则使用键为 key 的默认值创建一个 Action。该值标识在 Action 上调用 actionPerformed 时要加载的声音资源。声音资源通过 getClass().getResourceAsStream() 加载到 byte[] 中。

      参数:
      key - 识别音频动作的键
      返回:
      Action 用于播放源,或 null 如果 keynull
      自从:
      1.4
      参见:
    • playSound

      protected void playSound(Action  audioAction)
      如有必要,调用 audioAction 上的 actionPerformed 来播放声音。如果 "AuditoryCues.playList" 默认值是一个 non-null Object[] 包含一个 String 条目等于 audioAction 的名称,则调用 actionPerformed 方法。
      参数:
      audioAction - 一个 Action,它知道如何呈现与正在发生的系统或用户活动关联的音频; null 的值被忽略
      抛出:
      ClassCastException - 如果 audioActionnon-null 并且默认值 "AuditoryCues.playList" 不是 Object[]
      自从:
      1.4