public class ComponentView extends View
 该组件是根据返回的值,以相对于文本基线放置Component.getAlignmentY 。 对于Swing组件,可以使用方法JComponent.setAlignmentY方便地设置此值。 例如,设置值为0.75将导致75%的组件高于基线,25%的组件将低于基线。 
该类被实现为在多个线程的存在下(例如从异步通知模型更改)正常工作,确保所有组件访问都在事件线程上完成。
所使用的组件由createComponent方法的返回值确定。 此方法的默认实现是返回组件作为元素的属性(通过调用StyleConstants.getComponent)。 这种行为的局限性在于组件不能被多个文本组件使用(即使用共享模型)。 子类可以通过实现createComponent来删除此约束,以便根据属性中包含的某种规范实际创建组件。 html包中的ObjectView类是支持共享模型的多个组件视图的ComponentView实现的示例。
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXISBOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST| Constructor and Description | 
|---|
| ComponentView(Element elem)
              创建一个新的ComponentView对象。 
             | 
| Modifier and Type | Method and Description | 
|---|---|
| protected Component | createComponent()
              创建与此视图关联的组件。 
             | 
| float | getAlignment(int axis)
              确定沿着轴的该视图的所需对准。 
             | 
| Component | getComponent()
              获取与视图关联的组件。 
             | 
| float | getMaximumSpan(int axis)
              确定沿着轴的该视图的最大跨度。 
             | 
| float | getMinimumSpan(int axis)
              确定此视图沿轴的最小跨度。 
             | 
| float | getPreferredSpan(int axis)
              确定沿着轴的此视图的首选跨度。 
             | 
| Shape | modelToView(int pos, Shape a, Position.Bias b)
              提供从模型的坐标空间到视图的坐标空间的映射。 
             | 
| void | paint(Graphics g, Shape a)
              真正的绘画行为自然地发生在组件与其父容器(托管此视图的同一容器)的关联中。 
             | 
| void | setParent(View p)
              设置子视图的父级。 
             | 
| int | viewToModel(float x, float y, Shape a, Position.Bias[] bias)
              提供从视图坐标空间到模型的逻辑坐标空间的映射。 
             | 
append, breakView, changedUpdate, createFragment, forwardUpdate, forwardUpdateToView, getAttributes, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getNextVisualPositionFrom, getParent, getResizeWeight, getStartOffset, getToolTipText, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, insertUpdate, isVisible, modelToView, modelToView, preferenceChanged, remove, removeAll, removeUpdate, replace, setSize, updateChildren, updateLayout, viewToModelpublic ComponentView(Element elem)
elem - 要装饰的元素 
           protected Component createComponent()
public final Component getComponent()
public void paint(Graphics g, Shape a)
paint在 
            View 
           g - 图形上下文 
           a - 形状 
           View.paint(java.awt.Graphics, java.awt.Shape) 
           public float getPreferredSpan(int axis)
getPreferredSpan在 
            View 
           axis - 可以是View.X_AXIS或View.Y_AXIS 
           IllegalArgumentException - 针对无效轴 
           View.getPreferredSpan(int) 
           public float getMinimumSpan(int axis)
getMinimumSpan在 
            View 
           axis - 可以是View.X_AXIS或View.Y_AXIS 
           IllegalArgumentException - 对于无效轴 
           View.getPreferredSpan(int) 
           public float getMaximumSpan(int axis)
getMaximumSpan在 
            View 
           axis - 可以是View.X_AXIS或View.Y_AXIS 
           IllegalArgumentException - 针对无效轴 
           View.getPreferredSpan(int) 
           public float getAlignment(int axis)
getAlignment在 
            View 
           axis - 可以是View.X_AXIS或View.Y_AXIS 
           public void setParent(View p)
getContainer返回的值。 
           如果父视图参数为null,则此视图正在清除,因此该组件将从其父项中删除。 
           组件层次结构的更改将触及组件锁定,这是View层次结构中不安全的一件事情。 因此,如果在事件线程上执行,则会立即执行此功能,或者如果从另一个线程调用(如果从异步更新发生更改的通知),则会在事件队列中排队。
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException
modelToView在 
            View 
           pos - 转换> = 0的位置 
           a - 要分配的区域 
           b - 在位置是两个视图的边界的情况下,偏移朝向前一个字符或由偏移表示的下一个字符; 
            b将具有以下值之一: 
            Position.Bias.Forward Position.Bias.Backward BadLocationException - 如果给定的位置不表示相关文档中的有效位置 
           View.modelToView(int, java.awt.Shape, javax.swing.text.Position.Bias) 
           public int viewToModel(float x,
                       float y,
                       Shape a,
                       Position.Bias[] bias) 
          viewToModel在 
            View 
           x - X坐标> = 0 
           y - Y坐标> = 0 
           a - 要分配的区域 
           View.viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[]) 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.