java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.ButtonUI
javax.swing.plaf.MenuItemUI
javax.swing.plaf.basic.BasicMenuItemUI
基本菜单项实现
-
内部类总结
内部类 -
字段摘要
字段修饰符和类型Field描述protected String加速器分隔符字符串,例如'Ctrl+C'中的'+'。protected Font加速器字体。protected Color加速器前景的颜色。protected Color加速器选择的颜色。protected Icon箭头图标。protected Icon检查图标。protected int文本和图标之间的间隙。protected Color禁用前景的颜色。protected MenuDragMouseListenerMenuDragMouseListener的实例。protected JMenuItemJMenuItem的实例。protected MenuKeyListenerMenuKeyListener的实例。protected MouseInputListenerMouseInputListener的实例。protected boolean该值表示是否绘制了旧边框。protected PropertyChangeListenerPropertyChangeListener从createPropertyChangeListener返回。protected Color选择背景的颜色。protected Color选择前景的颜色。 -
构造方法总结
构造方法 -
方法总结
修饰符和类型方法描述protected MenuDragMouseListener返回MenuDragMouseListener的实例。protected MenuKeyListener返回MenuKeyListener的实例。protected MouseInputListener返回MouseInputListener的实例。protected PropertyChangeListener创建一个PropertyChangeListener,它将被添加到菜单项中。static ComponentUI返回BasicMenuItemUI的新实例。protected void当要激活菜单项时调用此方法。getPath()返回菜单元素路径。protected DimensiongetPreferredMenuItemSize(JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap) 返回菜单项的首选大小。protected String返回属性前缀。protected voidinstallComponents(JMenuItem menuItem) 注册菜单的子组件。protected void安装默认属性。protected void注册键盘操作。protected void注册听众。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 void呈现当前菜单项的文本。protected voiduninstallComponents(JMenuItem menuItem) 注销组件。protected void卸载默认属性。protected void注销键盘操作。protected void注销听众。voidupdate(Graphics g, JComponent c) 我们在 paintMenuItem() 中绘制背景,因此重写更新(默认填充不透明组件的背景)以仅调用 paint()。在类 javax.swing.plaf.ComponentUI 中声明的方法
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI
-
字段详细信息
-
selectionBackground
选择背景的颜色。 -
selectionForeground
选择前景的颜色。 -
disabledForeground
禁用前景的颜色。 -
acceleratorForeground
加速器前景的颜色。 -
acceleratorSelectionForeground
加速器选择的颜色。 -
acceleratorDelimiter
加速器分隔符字符串,例如'Ctrl+C'中的'+'。- 自从:
- 1.7
-
defaultTextIconGap
protected int defaultTextIconGap文本和图标之间的间隙。 -
acceleratorFont
加速器字体。 -
mouseInputListener
MouseInputListener的实例。 -
propertyChangeListener
PropertyChangeListener从createPropertyChangeListener返回。您不需要访问此字段,而是如果您想自定义PropertyChangeListeneroverridecreatePropertyChangeListener。- 自从:
- 1.6
- 参见:
-
arrowIcon
箭头图标。 -
checkIcon
检查图标。 -
oldBorderPainted
protected boolean oldBorderPainted该值表示是否绘制了旧边框。
-
构造方法详细信息
-
BasicMenuItemUI
public BasicMenuItemUI()构造一个BasicMenuItemUI
-
-
方法详情
-
createUI
返回BasicMenuItemUI的新实例。- 参数:
c- 一个组件- 返回:
BasicMenuItemUI的新实例
-
installDefaults
protected void installDefaults()安装默认属性。 -
installComponents
注册菜单的子组件。- 参数:
menuItem- 一个菜单项- 自从:
- 1.3
-
getPropertyPrefix
返回属性前缀。- 返回:
- 属性前缀
-
installListeners
protected void installListeners()注册听众。 -
installKeyboardActions
protected void installKeyboardActions()注册键盘操作。 -
uninstallDefaults
protected void uninstallDefaults()卸载默认属性。 -
uninstallComponents
注销组件。- 参数:
menuItem- 一个菜单项- 自从:
- 1.3
-
uninstallListeners
protected void uninstallListeners()注销听众。 -
uninstallKeyboardActions
protected void uninstallKeyboardActions()注销键盘操作。 -
createMouseInputListener
返回MouseInputListener的实例。- 参数:
c- 一个组件- 返回:
MouseInputListener的实例
-
createMenuDragMouseListener
返回MenuDragMouseListener的实例。- 参数:
c- 一个组件- 返回:
MenuDragMouseListener的实例
-
createMenuKeyListener
返回MenuKeyListener的实例。- 参数:
c- 一个组件- 返回:
MenuKeyListener的实例
-
createPropertyChangeListener
创建一个PropertyChangeListener,它将被添加到菜单项中。如果此方法返回 null,则不会将其添加到菜单项。- 参数:
c- 一个组件- 返回:
PropertyChangeListener的实例或 null- 自从:
- 1.6
-
getPreferredMenuItemSize
protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap) 返回菜单项的首选大小。- 参数:
c- 一个组件checkIcon- 复选图标arrowIcon- 箭头图标defaultTextIconGap- 文本和图标之间的间隙- 返回:
- 菜单项的首选大小
-
update
我们在 paintMenuItem() 中绘制背景,因此重写更新(默认填充不透明组件的背景)以仅调用 paint()。- 重写:
update在类ComponentUI中- 参数:
g- 绘制的Graphics上下文c- 正在绘制的组件;这个参数经常被忽略,但如果 UI 对象是无状态的并且由多个组件共享,则可能会被使用- 参见:
-
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
绘制菜单项的背景。- 参数:
g- 油漆图形menuItem- 要绘制的菜单项bgColor- 选择背景颜色- 自从:
- 1.4
-
paintText
呈现当前菜单项的文本。- 参数:
g- 图形上下文menuItem- 要呈现的菜单项textRect- 用于呈现文本的边界矩形text- 要呈现的字符串- 自从:
- 1.4
-
getPath
返回菜单元素路径。- 返回:
- 菜单元素路径
-
doClick
当要激活菜单项时调用此方法。此方法处理菜单项激活的一些细节,例如清除所选路径和向 JMenuItem 的 doClick() 方法发送消息。- 参数:
msm- 菜单选择管理器。视觉反馈和内部簿记任务委托给此 MenuSelectionManager。如果null作为此参数传递,则使用MenuSelectionManager.defaultManager。- 自从:
- 1.4
- 参见:
-