public class Box extends JComponent implements Accessible
Box
类可以创建影响布局的几种不可见组件:胶水,支柱和刚性区域。 如果您的Box
包含的所有组件均具有固定大小,则可能需要使用胶粘组件(由createGlue
返回)来控制组件的位置。 如果您需要两个组件之间的固定数量的空间,请尝试使用支柱( createHorizontalStrut
或createVerticalStrut
)。 如果您需要一个总共占用相同空间的createRigidArea
,请通过调用createRigidArea
。
如果要实现一个BoxLayout
,您可以找到进一步的信息和例子How to Use BoxLayout ,在Java教程的部分。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对于所有JavaBeans的长期存储的支持已经添加到java.beans
包中。 请参阅XMLEncoder
。
BoxLayout
Modifier and Type | Class and Description |
---|---|
protected class |
Box.AccessibleBox
这个类实现了可访问性支持
Box 类。
|
static class |
Box.Filler
参与布局但没有视图的轻量级组件的实现。
|
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
Box(int axis)
创建一个
Box ,它沿着指定的轴显示其组件。
|
Modifier and Type | Method and Description |
---|---|
static Component |
createGlue()
创建一个不可见的“胶水”组件,可在Box中使用,其可见组件具有最大宽度(对于水平框)或高度(对于垂直框)。
|
static Box |
createHorizontalBox()
创建一个
Box 显示其组件的Box。
|
static Component |
createHorizontalGlue()
创建水平胶水组件。
|
static Component |
createHorizontalStrut(int width)
创建一个看不见的,固定宽度的组件。
|
static Component |
createRigidArea(Dimension d)
创建一个总是指定大小的不可见组件。
|
static Box |
createVerticalBox()
创建一个
Box 显示其组件的Box。
|
static Component |
createVerticalGlue()
创建垂直胶水组件。
|
static Component |
createVerticalStrut(int height)
创建一个看不见的,固定高度的组件。
|
AccessibleContext |
getAccessibleContext()
获取与此Box关联的AccessibleContext。
|
protected void |
paintComponent(Graphics g)
Box 这个
Box 。
|
void |
setLayout(LayoutManager l)
抛出AWTError,因为Box只能使用BoxLayout。
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, 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, updateUI
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, transferFocusDownCycle, validate, validateTree
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, 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, getPeer, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public Box(int axis)
Box
,沿着指定的轴显示其组件。
axis
-可以是
BoxLayout.X_AXIS
,
BoxLayout.Y_AXIS
,
BoxLayout.LINE_AXIS
或
BoxLayout.PAGE_AXIS
。
AWTError
- 如果
axis
无效
createHorizontalBox()
,
createVerticalBox()
public static Box createHorizontalBox()
Box
,从左到右显示其组件。
如果你想有一个Box
尊重组件的方向,你应该创建Box
使用构造,并通过在BoxLayout.LINE_AXIS
,如:
Box lineBox = new Box(BoxLayout.LINE_AXIS);
public static Box createVerticalBox()
Box
显示其组件的Box。
如果你想有一个Box
尊重组件的方向,你应该创建Box
使用构造,并通过在BoxLayout.PAGE_AXIS
,如:
Box lineBox = new Box(BoxLayout.PAGE_AXIS);
public static Component createRigidArea(Dimension d)
d
- 不可见组件的尺寸
createGlue()
,
createHorizontalStrut(int)
,
createVerticalStrut(int)
public static Component createHorizontalStrut(int width)
width
- 不
width
的宽度,以像素为单位> = 0
createVerticalStrut(int)
,
createGlue()
,
createRigidArea(java.awt.Dimension)
public static Component createVerticalStrut(int height)
height
- 不
height
的高度,以像素为单位> = 0
createHorizontalStrut(int)
,
createGlue()
,
createRigidArea(java.awt.Dimension)
public static Component createGlue()
例如,假设您有一个包含两个固定大小组件的水平方框。 如果盒子获得额外的空间,固定大小的组件不会变大,那么额外的空间在哪里? 没有胶水,额外的空间就在第二个组件的右边。 如果您在固定大小的组件之间放置胶水,那么额外的空间就会放在那里。 如果在第一个固定尺寸的组件之前放置胶水,额外的空间就会到达,固定尺寸的组件被推到盒子的右边缘。 如果在第一个固定尺寸组件之前放置胶水,并且在第二个固定尺寸组件之后,固定尺寸组件在框中居中。
要使用胶水,请调用Box.createGlue
并将返回的组件添加到容器中。 胶水组件没有最小或优选的尺寸,因此除非有空间可用,否则不占用空间。 如果有多余的空间可用,那么胶水组件就可以获得可用的水平或垂直空间的份额,就像没有最大宽度或高度的任何其他组件一样。
public static Component createHorizontalGlue()
public static Component createVerticalGlue()
public void setLayout(LayoutManager l)
setLayout
在类别
Container
l
- 要使用的布局管理器
Container.doLayout()
,
Container.getLayout()
,
Container.invalidate()
protected void paintComponent(Graphics g)
Box
这个Box
。
如果这个Box
有一个UI,这个方法调用超级实现,否则如果这个Box
是不透明的, Graphics
使用背景填充Graphics。
paintComponent
在类别
JComponent
g
- 要绘画的
Graphics
NullPointerException
- 如果
g
为空
JComponent.paint(java.awt.Graphics)
, ComponentUI
public AccessibleContext getAccessibleContext()
getAccessibleContext
在界面
Accessible
getAccessibleContext
在类别
Component