- java.lang.Object
-
- javax.swing.plaf.ComponentUI
-
- javax.swing.plaf.ButtonUI
-
- javax.swing.plaf.MenuItemUI
-
- javax.swing.plaf.basic.BasicMenuItemUI
-
public class BasicMenuItemUI extends MenuItemUI
BasicMenuItem实现
-
-
嵌套类汇总
嵌套类 变量和类型 类 描述 protected classBasicMenuItemUI.MouseInputHandler鼠标输入处理程序
-
字段汇总
字段 变量和类型 字段 描述 protected StringacceleratorDelimiter加速器分隔符字符串,例如'+'位于'Ctrl+C'。protected FontacceleratorFont加速器字体。protected ColoracceleratorForeground加速器前景的颜色。protected ColoracceleratorSelectionForeground加速器选择的颜色。protected IconarrowIcon箭头图标。protected IconcheckIcon检查图标。protected intdefaultTextIconGap文本和图标之间的差距。protected ColordisabledForeground禁用前景的颜色。protected MenuDragMouseListenermenuDragMouseListenerMenuDragMouseListener的实例。protected JMenuItemmenuItemJMenuItem的实例。protected MenuKeyListenermenuKeyListenerMenuKeyListener的实例。protected MouseInputListenermouseInputListenerMouseInputListener的实例。protected booleanoldBorderPainted该值表示是否绘制了旧边框。protected PropertyChangeListenerpropertyChangeListenerPropertyChangeListener从createPropertyChangeListener返回。protected ColorselectionBackground选择背景的颜色。protected ColorselectionForeground选择前景的颜色。
-
构造方法摘要
构造方法 构造器 描述 BasicMenuItemUI()
-
方法摘要
所有方法 静态方法 实例方法 具体的方法 变量和类型 方法 描述 protected MenuDragMouseListenercreateMenuDragMouseListener(JComponent c)返回MenuDragMouseListener的实例。protected MenuKeyListenercreateMenuKeyListener(JComponent c)返回MenuKeyListener的实例。protected MouseInputListenercreateMouseInputListener(JComponent c)返回MouseInputListener的实例。protected PropertyChangeListenercreatePropertyChangeListener(JComponent c)创建一个PropertyChangeListener,它将添加到菜单项中。static ComponentUIcreateUI(JComponent c)返回BasicMenuItemUI的新实例。protected voiddoClick(MenuSelectionManager msm)要激活菜单项时调用此方法。MenuElement[]getPath()返回菜单元素路径。protected DimensiongetPreferredMenuItemSize(JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap)返回菜单项的首选大小。protected StringgetPropertyPrefix()返回属性前缀。protected voidinstallComponents(JMenuItem menuItem)protected voidinstallDefaults()安装默认属性。protected voidinstallKeyboardActions()注册键盘操作。protected voidinstallListeners()注册听众。protected voidpaintBackground(Graphics g, JMenuItem menuItem, Color bgColor)绘制菜单项的背景。protected voidpaintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap)绘制菜单项。protected voidpaintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text)呈现当前菜单项的文本。protected voiduninstallComponents(JMenuItem menuItem)取消注册组件。protected voiduninstallDefaults()卸载默认属性。protected voiduninstallKeyboardActions()取消注册键盘操作。protected voiduninstallListeners()取消注册听众。voidupdate(Graphics g, JComponent c)我们在paintMenuItem()中绘制背景,因此覆盖更新(默认情况下填充不透明组件的背景)只调用paint()。-
声明方法的类 javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI
-
-
-
-
字段详细信息
-
menuItem
protected JMenuItem menuItem
JMenuItem的实例。
-
selectionBackground
protected Color selectionBackground
选择背景的颜色。
-
selectionForeground
protected Color selectionForeground
选择前景的颜色。
-
disabledForeground
protected Color disabledForeground
禁用前景的颜色。
-
acceleratorForeground
protected Color acceleratorForeground
加速器前景的颜色。
-
acceleratorSelectionForeground
protected Color acceleratorSelectionForeground
加速器选择的颜色。
-
acceleratorDelimiter
protected String acceleratorDelimiter
加速器分隔符字符串,例如'+'在'Ctrl+C'。- 从以下版本开始:
- 1.7
-
defaultTextIconGap
protected int defaultTextIconGap
文本和图标之间的差距。
-
acceleratorFont
protected Font acceleratorFont
加速器字体。
-
mouseInputListener
protected MouseInputListener mouseInputListener
MouseInputListener的实例。
-
menuDragMouseListener
protected MenuDragMouseListener menuDragMouseListener
MenuDragMouseListener的实例。
-
menuKeyListener
protected MenuKeyListener menuKeyListener
MenuKeyListener的实例。
-
propertyChangeListener
protected PropertyChangeListener propertyChangeListener
PropertyChangeListener从createPropertyChangeListener返回。 您不需要访问此字段,而是要自定义PropertyChangeListener覆盖createPropertyChangeListener。- 从以下版本开始:
- 1.6
- 另请参见:
-
createPropertyChangeListener(javax.swing.JComponent)
-
arrowIcon
protected Icon arrowIcon
箭头图标。
-
checkIcon
protected Icon checkIcon
检查图标。
-
oldBorderPainted
protected boolean oldBorderPainted
该值表示是否绘制了旧边框。
-
-
方法详细信息
-
createUI
public static ComponentUI createUI(JComponent c)
返回BasicMenuItemUI的新实例。- 参数
-
c- 一个组件 - 结果
-
BasicMenuItemUI的新实例
-
installDefaults
protected void installDefaults()
安装默认属性。
-
installComponents
protected void installComponents(JMenuItem menuItem)
- 参数
-
menuItem- 菜单项 - 从以下版本开始:
- 1.3
-
getPropertyPrefix
protected String getPropertyPrefix()
返回属性前缀。- 结果
- 属性前缀
-
installListeners
protected void installListeners()
注册听众。
-
installKeyboardActions
protected void installKeyboardActions()
注册键盘操作。
-
uninstallDefaults
protected void uninstallDefaults()
卸载默认属性。
-
uninstallComponents
protected void uninstallComponents(JMenuItem menuItem)
取消注册组件。- 参数
-
menuItem- 菜单项 - 从以下版本开始:
- 1.3
-
uninstallListeners
protected void uninstallListeners()
取消注册听众。
-
uninstallKeyboardActions
protected void uninstallKeyboardActions()
取消注册键盘操作。
-
createMouseInputListener
protected MouseInputListener createMouseInputListener(JComponent c)
返回MouseInputListener的实例。- 参数
-
c- 一个组件 - 结果
-
MouseInputListener一个实例
-
createMenuDragMouseListener
protected MenuDragMouseListener createMenuDragMouseListener(JComponent c)
返回MenuDragMouseListener的实例。- 参数
-
c- 一个组件 - 结果
-
MenuDragMouseListener一个实例
-
createMenuKeyListener
protected MenuKeyListener createMenuKeyListener(JComponent c)
返回MenuKeyListener的实例。- 参数
-
c- 一个组件 - 结果
-
MenuKeyListener一个实例
-
createPropertyChangeListener
protected PropertyChangeListener createPropertyChangeListener(JComponent c)
创建一个PropertyChangeListener,它将添加到菜单项中。 如果此方法返回null,则不会将其添加到菜单项。- 参数
-
c- 一个组件 - 结果
-
PropertyChangeListener的实例或null - 从以下版本开始:
- 1.6
-
getPreferredMenuItemSize
protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap)
返回菜单项的首选大小。- 参数
-
c- 一个组件 -
checkIcon- 一个检查图标 -
arrowIcon- 箭头图标 -
defaultTextIconGap- 文本和图标之间的间隙 - 结果
- 菜单项的首选大小
-
update
public void update(Graphics g, JComponent c)
我们在paintMenuItem()中绘制背景,因此覆盖更新(默认情况下填充不透明组件的背景)只调用paint()。- 重写:
-
update类ComponentUI - 参数
-
g- 要绘制的Graphics上下文 -
c- 正在绘制的组件; 此参数通常被忽略,但如果UI对象是无状态的并且由多个组件共享,则可以使用此参数 - 另请参见:
-
ComponentUI.paint(java.awt.Graphics, javax.swing.JComponent),JComponent.paintComponent(java.awt.Graphics)
-
paintMenuItem
protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap)
绘制菜单项。- 参数
-
g-实例Graphics -
c- 一个组件 -
checkIcon- 一个检查图标 -
arrowIcon- 箭头图标 -
background- 背景颜色 -
foreground- 前景色 -
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的doClick()方法。- 参数
-
msm- MenuSelectionManager。 视觉反馈和内部簿记任务被委托给此MenuSelectionManager。 如果将null作为此参数传递,则使用MenuSelectionManager.defaultManager。 - 从以下版本开始:
- 1.4
- 另请参见:
-
MenuSelectionManager,AbstractButton.doClick(int)
-
-