public class Box extends JComponent implements Accessible
Box クラスは、レイアウトに影響する数種類の不可視コンポーネントを作成できます。接着剤 (glue)、柱 (strut)、固定領域 (rigid area) などです。Box に含まれるすべてのコンポーネントのサイズが固定されている場合は、createGlue が返す接着剤コンポーネントを使って、コンポーネントの位置を制御できます。2 つのコンポーネントの間に一定の空間が必要な場合は、柱を使ってみることをお勧めします (createHorizontalStrut または createVerticalStrut)。常に同じ量の空間を占める不可視コンポーネントが必要な場合は、createRigidArea を呼び出すことで、そのコンポーネントを取得します。
 
BoxLayout を実装する場合、詳細な情報と例については、『The Java Tutorial』の「How to Use BoxLayout」を参照してください。
 
警告: このクラスの直列化されたオブジェクトは、今後の Swing リリースと互換ではなくなる予定です。現在の直列化のサポートは、短期間の格納や、同じバージョンの Swing を実行するアプリケーション間の RMI に適しています。1.4 以降、すべての JavaBeansTM 用の長期間の格納サポートが java.beans パッケージに追加されています。XMLEncoder を参照してください。
BoxLayout| 修飾子と型 | クラスと説明 | 
|---|---|
| protected class  | Box.AccessibleBoxこのクラスは  Boxクラスのアクセシビリティーサポートを実装しています。 | 
| static class  | Box.Fillerレイアウトに含まれるがビューを持たない軽量コンポーネントの実装です。 | 
JComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategyaccessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWBOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| コンストラクタと説明 | 
|---|
| Box(int axis)指定された軸に沿ってコンポーネントを表示する  Boxを生成します。 | 
| 修飾子と型 | メソッドと説明 | 
|---|---|
| static Component | createGlue()不可視の「接着剤」コンポーネントを作成します。これは、可視コンポーネントに水平ボックスに対する最大幅や垂直ボックスに対する最大高が指定されている Box に便利です。 | 
| static Box | createHorizontalBox()コンポーネントを左から右へ表示する  Boxを生成します。 | 
| static Component | createHorizontalGlue()水平方向の接着剤コンポーネントを作成します。 | 
| static Component | createHorizontalStrut(int width)不可視の固定幅コンポーネントを生成します。 | 
| static Component | createRigidArea(Dimension d)常に指定されたサイズである、不可視コンポーネントを生成します。 | 
| static Box | createVerticalBox()コンポーネントを上から下へ表示する  Boxを生成します。 | 
| static Component | createVerticalGlue()垂直方向の接着剤コンポーネントを作成します。 | 
| static Component | createVerticalStrut(int height)不可視の、高さが固定されたコンポーネントを作成します。 | 
| AccessibleContext | getAccessibleContext()このボックスに関連付けられた AccessibleContext を取得します。 | 
| protected void | paintComponent(Graphics g)この  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, updateUIadd, 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, validateTreeaction, 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, transferFocusUpCyclepublic 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 を生成し 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 - 不可視コンポーネントのピクセル単位の幅。値はゼロ以上createVerticalStrut(int), createGlue(), createRigidArea(java.awt.Dimension)public static Component createVerticalStrut(int height)
height - 不可視コンポーネントのピクセル単位の高さ。値はゼロ以上createHorizontalStrut(int), createGlue(), createRigidArea(java.awt.Dimension)public static Component createGlue()
たとえば、1 つの水平ボックスに、固定サイズのコンポーネントが 2 つ含まれているとします。このボックスに空間が追加されても、固定サイズコンポーネントは大きくなりません。このとき、接着剤がない場合、2 番目のコンポーネントの右の空間が余ります。ここで接着剤を固定サイズコンポーネントの間に置くと、余った空間を接着剤コンポーネントが占めます。接着剤を 1 番目の固定サイズコンポーネントの前に置くと、余った空間を接着剤コンポーネントが占め、2 つの固定サイズコンポーネントはボックスの右に寄せられます。1 番目の固定サイズコンポーネントの前、および 2 番目の固定サイズコンポーネントのあとに接着剤を置くと、2 つの固定サイズコンポーネントはボックスの中央に寄せられます。
接着剤を使うには、Box.createGlue を呼び出して、返されたコンポーネントをコンテナに追加します。接着剤コンポーネントには、最小のサイズ、あるいは適切なサイズがありません。そのため、余分な空間がないかぎり、空間を占めることはありません。余分な空間があれば、接着剤コンポーネントは、水平方向、または垂直方向の利用可能な空間を占めます。これは、幅あるいは高さの最大値の指定がないコンポーネントと同様です。
public static Component createHorizontalGlue()
public static Component createVerticalGlue()
public void setLayout(LayoutManager l)
setLayout 、クラス:  Containerl - 使用するレイアウトマネージャーContainer.doLayout(), Container.getLayout(), Container.invalidate()protected void paintComponent(Graphics g)
Box をペイントします。この Box に UI がある場合、このメソッドは上位実装を呼び出します。この Box が不透明な場合、Graphics はバックグラウンドカラーで塗りつぶされます。paintComponent 、クラス:  JComponentg - ペイントされる GraphicsNullPointerException - g が null である場合JComponent.paint(java.awt.Graphics), ComponentUIpublic AccessibleContext getAccessibleContext()
getAccessibleContext 、インタフェース: AccessiblegetAccessibleContext 、クラス:  JComponent バグまたは機能を送信 
詳細な API リファレンスおよび開発者ドキュメントについては、Java SE のドキュメントを参照してください。そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright © 1993, 2013, Oracle and/or its affiliates. All rights reserved.