JavaTM Platform
Standard Ed. 6

javax.swing.plaf.basic
类 BasicMenuItemUI

java.lang.Object
  继承者 javax.swing.plaf.ComponentUI
      继承者 javax.swing.plaf.ButtonUI
          继承者 javax.swing.plaf.MenuItemUI
              继承者 javax.swing.plaf.basic.BasicMenuItemUI
直接已知子类:
BasicCheckBoxMenuItemUI, BasicMenuUI, BasicRadioButtonMenuItemUI

public class BasicMenuItemUI
extends MenuItemUI

BasicMenuItem 实现


嵌套类摘要
protected  class BasicMenuItemUI.MouseInputHandler
           
 
字段摘要
protected  Font acceleratorFont
           
protected  Color acceleratorForeground
           
protected  Color acceleratorSelectionForeground
           
protected  Icon arrowIcon
           
protected  Icon checkIcon
           
protected  int defaultTextIconGap
           
protected  Color disabledForeground
           
protected  MenuDragMouseListener menuDragMouseListener
           
protected  JMenuItem menuItem
           
protected  MenuKeyListener menuKeyListener
           
protected  MouseInputListener mouseInputListener
           
protected  boolean oldBorderPainted
           
protected  PropertyChangeListener propertyChangeListener
          从 createPropertyChangeListener 返回的 PropertyChangeListener
protected  Color selectionBackground
           
protected  Color selectionForeground
           
 
构造方法摘要
BasicMenuItemUI()
           
 
方法摘要
protected  MenuDragMouseListener createMenuDragMouseListener(JComponent c)
           
protected  MenuKeyListener createMenuKeyListener(JComponent c)
           
protected  MouseInputListener createMouseInputListener(JComponent c)
           
protected  PropertyChangeListener createPropertyChangeListener(JComponent c)
          创建一个将被添加到菜单项的 PropertyChangeListener
static ComponentUI createUI(JComponent c)
           
protected  void doClick(MenuSelectionManager msm)
          要激活菜单项时调用此方法。
 Dimension getMaximumSize(JComponent c)
          返回指定组件的适合外观的最大大小。
 Dimension getMinimumSize(JComponent c)
          返回指定组件的适合外观的最小大小。
 MenuElement[] getPath()
           
protected  Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap)
           
 Dimension getPreferredSize(JComponent c)
          返回指定组件的适合外观的首选大小。
protected  String getPropertyPrefix()
           
protected  void installComponents(JMenuItem menuItem)
           
protected  void installDefaults()
           
protected  void installKeyboardActions()
           
protected  void installListeners()
           
 void installUI(JComponent c)
          配置指定组件,使其适合外观。
 void paint(Graphics g, JComponent c)
          绘制指定组件,使其适合外观。
protected  void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)
          绘制菜单项的背景。
protected  void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap)
           
protected  void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text)
          呈现当前菜单项的文本。
protected  void uninstallComponents(JMenuItem menuItem)
           
protected  void uninstallDefaults()
           
protected  void uninstallKeyboardActions()
           
protected  void uninstallListeners()
           
 void uninstallUI(JComponent c)
          在 installUI 期间,在指定组件上反向执行的配置操作。
 void update(Graphics g, JComponent c)
          使用 paintMenuItem() 绘制背景,从而重写 update(默认情况下填充不透明组件的背景)以调用 paint()。
 
从类 javax.swing.plaf.ComponentUI 继承的方法
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

menuItem

protected JMenuItem menuItem

selectionBackground

protected Color selectionBackground

selectionForeground

protected Color selectionForeground

disabledForeground

protected Color disabledForeground

acceleratorForeground

protected Color acceleratorForeground

acceleratorSelectionForeground

protected Color acceleratorSelectionForeground

defaultTextIconGap

protected int defaultTextIconGap

acceleratorFont

protected Font acceleratorFont

mouseInputListener

protected MouseInputListener mouseInputListener

menuDragMouseListener

protected MenuDragMouseListener menuDragMouseListener

menuKeyListener

protected MenuKeyListener menuKeyListener

propertyChangeListener

protected PropertyChangeListener propertyChangeListener
createPropertyChangeListener 返回的 PropertyChangeListener。不需要访问此字段,如果想要定制 PropertyChangeListener,则重写 createPropertyChangeListener

从以下版本开始:
1.6
另请参见:
createPropertyChangeListener(javax.swing.JComponent)

arrowIcon

protected Icon arrowIcon

checkIcon

protected Icon checkIcon

oldBorderPainted

protected boolean oldBorderPainted
构造方法详细信息

BasicMenuItemUI

public BasicMenuItemUI()
方法详细信息

createUI

public static ComponentUI createUI(JComponent c)

installUI

public void installUI(JComponent c)
从类 ComponentUI 复制的描述
配置指定组件,使其适合外观。当 ComponentUI 实例将作为 UI 委托安装在指定组件上时,可调用此方法。此方法应该为外观完整地配置组件,包括以下方面:
  1. 在组件上安装用于颜色、字体、边框、图标、不透明性等方面的所有默认属性值。只要有可能,就 应该重写由客户端程序初始化的属性值。
  2. 如有必要,可在组件上安装一个 LayoutManager
  3. 将所需的所有子组件创建/添加到组件中。
  4. 在组件上创建/安装事件侦听器。
  5. 为了检测和适当响应组件属性更改,可在组件上创建/安装一个 PropertyChangeListener
  6. 在组件上安装键盘 UI(助记符、遍历等等)。
  7. 初始化任何适当的实例数据。

覆盖:
ComponentUI 中的 installUI
参数:
c - 将安装此 UI 委托的组件
另请参见:
ComponentUI.uninstallUI(javax.swing.JComponent), JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()

installDefaults

protected void installDefaults()

installComponents

protected void installComponents(JMenuItem menuItem)
从以下版本开始:
1.3

getPropertyPrefix

protected String getPropertyPrefix()

installListeners

protected void installListeners()

installKeyboardActions

protected void installKeyboardActions()

uninstallUI

public void uninstallUI(JComponent c)
从类 ComponentUI 复制的描述
installUI 期间,在指定组件上反向执行的配置操作。当此 UIComponent 实例将作为 UI 委托从指定组件上移除时,可调用此方法。此方法应该取消在 installUI 中执行的配置操作,非常小心地使 JComponent 实例处于某种洁净状态(没有额外的侦听器、没有特定于外观的属性对象等等)。配置内容应该包括以下方面:
  1. 从组件中移除所有 UI 设置的边框。
  2. 从组件上移除所有 UI 设置的布局管理器。
  3. 从组件中移除所有 UI 添加的子组件。
  4. 从组件中移除所有 UI 添加的事件/属性侦听器。
  5. 从组件中移除所有 UI 安装的键盘 UI。
  6. 使所有已分配的实例数据对象无效,从而允许进行 GC 操作。

覆盖:
ComponentUI 中的 uninstallUI
参数:
c - 从中移除此 UI 委托的组件;此参数常被忽略,但如果 UI 对象是无状态的并由多个组件共享,则可以使用该参数
另请参见:
ComponentUI.installUI(javax.swing.JComponent), JComponent.updateUI()

uninstallDefaults

protected void uninstallDefaults()

uninstallComponents

protected void uninstallComponents(JMenuItem menuItem)
从以下版本开始:
1.3

uninstallListeners

protected void uninstallListeners()

uninstallKeyboardActions

protected void uninstallKeyboardActions()

createMouseInputListener

protected MouseInputListener createMouseInputListener(JComponent c)

createMenuDragMouseListener

protected MenuDragMouseListener createMenuDragMouseListener(JComponent c)

createMenuKeyListener

protected MenuKeyListener createMenuKeyListener(JComponent c)

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener(JComponent c)
创建一个将被添加到菜单项的 PropertyChangeListener。如果此方法返回 null,则它将不会被添加到菜单项。

返回:
PropertyChangeListener 的实例或 null
从以下版本开始:
1.6

getMinimumSize

public Dimension getMinimumSize(JComponent c)
从类 ComponentUI 复制的描述
返回指定组件的适合外观的最小大小。如果返回 null,则最小大小将由组件的布局管理器计算(对于安装了特定布局管理器的组件而言,这是首选方法)。此方法的默认实现调用 getPreferredSize 并返回该值。

覆盖:
ComponentUI 中的 getMinimumSize
参数:
c - 将查询其最小大小的组件;此参数常被忽略,但如果 UI 对象是无状态的并由多个组件共享,则可以使用该参数
返回:
一个 Dimension 对象或 null
另请参见:
JComponent.getMinimumSize(), LayoutManager.minimumLayoutSize(java.awt.Container), ComponentUI.getPreferredSize(javax.swing.JComponent)

getPreferredSize

public Dimension getPreferredSize(JComponent c)
从类 ComponentUI 复制的描述
返回指定组件的适合外观的首选大小。如果返回 null,则首选大小将由组件的布局管理器计算(对于安装了特定布局管理器的组件而言,这是首选方法)。此方法的默认实现返回 null

覆盖:
ComponentUI 中的 getPreferredSize
参数:
c - 将查询其首选大小的组件;此参数常被忽略,但如果 UI 对象是无状态的并由多个组件共享,则可以使用该参数
另请参见:
JComponent.getPreferredSize(), LayoutManager.preferredLayoutSize(java.awt.Container)

getMaximumSize

public Dimension getMaximumSize(JComponent c)
从类 ComponentUI 复制的描述
返回指定组件的适合外观的最大大小。如果返回 null,则最大大小将由组件的布局管理器计算(对于安装了特定布局管理器的组件而言,这是首选方法)。此方法的默认实现调用 getPreferredSize 并返回该值。

覆盖:
ComponentUI 中的 getMaximumSize
参数:
c - 将查询其最大大小的组件;此参数常被忽略,但如果 UI 对象是无状态的并由多个组件共享,则可以使用该参数
返回:
一个 Dimension 对象或 null
另请参见:
JComponent.getMaximumSize(), LayoutManager2.maximumLayoutSize(java.awt.Container)

getPreferredMenuItemSize

protected Dimension getPreferredMenuItemSize(JComponent c,
                                             Icon checkIcon,
                                             Icon arrowIcon,
                                             int defaultTextIconGap)

update

public void update(Graphics g,
                   JComponent c)
使用 paintMenuItem() 绘制背景,从而重写 update(默认情况下填充不透明组件的背景)以调用 paint()。

覆盖:
ComponentUI 中的 update
参数:
g - 将在其中进行绘制的 Graphics 上下文
c - 将绘制的组件;此参数常被忽略,但如果 UI 对象是无状态的并由多个组件共享,则可以使用该参数
另请参见:
ComponentUI.paint(java.awt.Graphics, javax.swing.JComponent), JComponent.paintComponent(java.awt.Graphics)

paint

public void paint(Graphics g,
                  JComponent c)
从类 ComponentUI 复制的描述
绘制指定组件,使其适合外观。在将要绘制指定组件时,从 ComponentUI.update 方法中调用此方法。子类应该重写此方法并使用指定 Graphics 对象来呈现组件的内容。

覆盖:
ComponentUI 中的 paint
参数:
g - 将在其中进行绘制的 Graphics 上下文
c - 将绘制的组件;此参数常被忽略,但如果 UI 对象是无状态的并由多个组件共享,则可以使用该参数
另请参见:
ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)

paintMenuItem

protected void paintMenuItem(Graphics g,
                             JComponent c,
                             Icon checkIcon,
                             Icon arrowIcon,
                             Color background,
                             Color foreground,
                             int defaultTextIconGap)

paintBackground

protected void paintBackground(Graphics g,
                               JMenuItem menuItem,
                               Color bgColor)
绘制菜单项的背景。

参数:
g - 绘制图形
menuItem - 要绘制的菜单项
bgColor - 选择背景色
从以下版本开始:
1.4

paintText

protected void paintText(Graphics g,
                         JMenuItem menuItem,
                         Rectangle textRect,
                         String text)
呈现当前菜单项的文本。

参数:
g - 图形上下文
menuItem - 要呈现的菜单项
textRect - 用于呈现文本的边界矩形
text - 要呈现的字符串
从以下版本开始:
1.4

getPath

public MenuElement[] getPath()

doClick

protected void doClick(MenuSelectionManager msm)
要激活菜单项时调用此方法。此方法处理某些菜单项激活的细节,如清除所选路径和传递 JMenuItem's doClick() 方法的消息。

参数:
msm - MenuSelectionManager。将可视化反馈和内部簿记任务委托给此 MenuSelectionManager。如果将 null 作为此方法的参数传递,则使用 MenuSelectionManager.defaultManager
从以下版本开始:
1.4
另请参见:
MenuSelectionManager, AbstractButton.doClick(int)

JavaTM Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策