java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
javax.swing.JSpinner.DefaultEditor
- 所有已实现的接口:
-
ImageObserver
,LayoutManager
,MenuContainer
,PropertyChangeListener
,Serializable
,EventListener
,Accessible
,ChangeListener
- 封装类:
-
JSpinner
public static class JSpinner.DefaultEditor extends JPanel implements ChangeListener, PropertyChangeListener, LayoutManager
一个简单的基类,用于更专业的编辑器,显示模型当前值的只读视图,带有一个
JFormattedTextField
。子类可以配置JFormattedTextField
以创建适合其支持的模型类型的编辑器,并且可能需要覆盖stateChanged
和propertyChanged
方法,以保持模型和文本字段同步。
此类定义了一个dismiss
方法,从其所属的JSpinner
中移除编辑器的ChangeListener
。 setEditor
方法知道关于DefaultEditor.dismiss
,因此如果开发人员替换了一个派生自JSpinner.DefaultEditor
的编辑器,其ChangeListener
连接回到JSpinner
将被移除。但是在那之后,开发人员需要管理他们的编辑器监听器。类似地,如果子类覆盖了createEditor
,则子类需要处理其编辑器随后被替换(使用setEditor
)。我们期望在大多数情况下,通过setEditor
安装的编辑器或由createEditor
覆盖创建的编辑器将不会被替换。
此类是其单个JFormattedTextField
子级的LayoutManager
。默认情况下,子级只是与父级的插图居中。
- 自1.4版本起:
- 1.4
-
Nested Class Summary
Nested classes/interfaces declared in class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addLayoutComponent
(String name, Component child) 此LayoutManager
方法不执行任何操作。void
将当前编辑的值推送到SpinnerModel
。void
从指定的JSpinner
断开this
编辑器。int
getBaseline
(int width, int height) 返回基线。返回一个枚举,指示组件的基线随大小更改而更改的方式。返回此编辑器的JSpinner
祖先,如果没有祖先是JSpinner
,则返回null
。返回此编辑器的JFormattedTextField
子级。void
layoutContainer
(Container parent) 调整一个(唯一的)子级的大小,使其完全填充父级插图区域。minimumLayoutSize
(Container parent) 返回第一个(唯一的)子级的最小大小加上父级插图的大小。preferredLayoutSize
(Container parent) 返回第一个(唯一的)子级的首选大小加上父级插图的大小。void
被JFormattedTextField
的PropertyChangeListener
调用。void
removeLayoutComponent
(Component child) 此LayoutManager
方法不执行任何操作。void
当微调器的模型状态更改时调用此方法。Methods declared in class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods declared in class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods declared in class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
DefaultEditor
为指定的JSpinner
构造一个编辑器组件。此DefaultEditor
是其自身的布局管理器,并添加到微调器的ChangeListener
列表中。构造函数创建一个单个的JFormattedTextField
子级,将其值初始化为微调器模型的当前值,并将其添加到this
DefaultEditor
中。- 参数:
-
spinner
- 将监视this
编辑器的微调器模型 - 另请参阅:
-
-
Method Details
-
dismiss
从指定的JSpinner
断开this
编辑器。默认情况下,此方法会从微调器的ChangeListener
列表中移除自身。- 参数:
-
spinner
- 要从中断开此编辑器的JSpinner
;与传递给构造函数的微调器相同。
-
getSpinner
返回此编辑器的JSpinner
祖先,如果没有祖先是JSpinner
,则返回null
。通常,编辑器的父级是一个JSpinner
,但是JSpinner
的子类可能会覆盖createEditor
方法,并在JSpinner
和其编辑器之间插入一个或多个容器。- 返回:
-
JSpinner
祖先;如果没有祖先是JSpinner
,则返回null
- 另请参阅:
-
getTextField
返回此编辑器的JFormattedTextField
子级。默认情况下,文本字段是编辑器的第一个且唯一的子级。- 返回:
-
提供用户访问
SpinnerDateModel
值的JFormattedTextField
。 - 另请参阅:
-
stateChanged
当微调器的模型状态更改时调用此方法。将文本字段的value
设置为微调器模型的当前值。- 指定者:
-
stateChanged
在接口ChangeListener
中 - 参数:
-
e
- 其源为已更改模型的JSpinner
的ChangeEvent
。 - 另请参阅:
-
propertyChange
由JFormattedTextField
的PropertyChangeListener
调用。当"value"
属性更改时,这意味着用户已键入新数字,我们将微调器模型的值设置为值。此类忽略源不是
JFormattedTextField
的PropertyChangeEvents
,因此子类可以安全地将this
DefaultEditor
设置为其他对象的PropertyChangeListener
。- 指定者:
-
propertyChange
在接口PropertyChangeListener
中 - 参数:
-
e
- 其源为此类创建的JFormattedTextField
的PropertyChangeEvent
。 - 另请参阅:
-
addLayoutComponent
此LayoutManager
方法不执行任何操作。我们只管理一个单个子级,不支持布局约束。- 指定者:
-
addLayoutComponent
在接口LayoutManager
中 - 参数:
-
name
- 忽略 -
child
- 忽略
-
removeLayoutComponent
此LayoutManager
方法不执行任何操作。没有每个子级的状态。- 指定者:
-
removeLayoutComponent
在接口LayoutManager
中 - 参数:
-
child
- 忽略
-
preferredLayoutSize
返回第一个(唯一的)子级的首选大小加上父级插图的大小。- 指定者:
-
preferredLayoutSize
在接口LayoutManager
中 - 参数:
-
parent
- 管理布局的容器 - 返回:
- 用于布置指定容器的子组件的首选尺寸。
- 另请参阅:
-
minimumLayoutSize
返回第一个(唯一的)子级的最小大小加上父级插图的大小。- 指定者:
-
minimumLayoutSize
在接口LayoutManager
中 - 参数:
-
parent
- 管理布局的容器 - 返回值:
- 需要布局指定容器的子组件的最小尺寸。
- 参见:
-
layoutContainer
将一个(唯一的)子组件调整大小以完全填充父容器内边距的区域。- 指定者:
-
layoutContainer
在接口LayoutManager
中 - 参数:
-
parent
- 要布局的容器
-
commitEdit
将当前编辑的值推送到SpinnerModel
。默认实现会在
JFormattedTextField
上调用commitEdit
。- 抛出:
-
ParseException
- 如果编辑的值不合法
-
getBaseline
public int getBaseline(int width, int height) 返回基线。- 覆盖:
-
getBaseline
在类JComponent
中 - 参数:
-
width
- 获取基线的宽度 -
height
- 获取基线的高度 - 返回值:
- 基线或< 0表示没有合理的基线
- 抛出:
-
IllegalArgumentException
- 如果宽度或高度< 0 - 自从:
- 1.6
- 参见:
-
getBaselineResizeBehavior
返回一个枚举,指示组件的基线随尺寸变化而变化的方式。- 覆盖:
-
getBaselineResizeBehavior
在类JComponent
中 - 返回值:
- 一个枚举,指示组件尺寸变化时基线的变化方式
- 自从:
- 1.6
- 参见:
-