SalesPoint v3.3 API

util.swing
Class JOptionPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by util.swing.JOptionPanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class JOptionPanel
extends JPanel

A Swing Panel realising a standard option panel layout. That means, option titles are displayed right in front of their corresponding components. All alignment is done automatically.

Since:
v3.3
Author:
Thomas Ryssel
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int BOTTOM
          Constant representing bottom alignment.
static int CENTER
          Constant representing center alignment.
static int LEFT
          Constant representing left alignment.
static int RIGHT
          Constant representing right alignment.
static int TOP
          Constant representing top alignment.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JOptionPanel()
          Create a new JOptionPanel without title and horizontal and vertical alignment set to LEFT and TOP, respectively.
JOptionPanel(String text)
          Create a new JOptionPanel with horizontal and vertical alignment set to LEFT and TOP, respectively.
JOptionPanel(String text, int hgap, int vgap)
          Create a new JOptionPanel with horizontal and vertical alignment set to LEFT and TOP, respectively.
JOptionPanel(String text, int hgap, int vgap, int horizAlign, int vertAlign)
          Create a new JOptionPanel.
 
Method Summary
 void addOption(String title, JComponent component)
          Add the given component under the given title.
 void addOption(String title, Object text)
          Add a "display only" option. the text's toString() method will be used to construct a JLabel that will be displayed.
 Component getOptionComponent(int n)
          Get the n-th option component (in the order they were added).
 String getText()
          Get the option panel's title text.
 void setLayout(LayoutManager mgr)
          Set layout manager.
 void setText(String text)
          Set the option panel's title text.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, 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 inherited from 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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from 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, 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, hide, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CENTER

public static final int CENTER
Constant representing center alignment.

See Also:
Constant Field Values

LEFT

public static final int LEFT
Constant representing left alignment.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Constant representing right alignment.

See Also:
Constant Field Values

TOP

public static final int TOP
Constant representing top alignment.

See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
Constant representing bottom alignment.

See Also:
Constant Field Values
Constructor Detail

JOptionPanel

public JOptionPanel()
Create a new JOptionPanel without title and horizontal and vertical alignment set to LEFT and TOP, respectively. Horizontal gap will be 16 (pixels) and vertical gap will be set to 4 (pixels).


JOptionPanel

public JOptionPanel(String text)
Create a new JOptionPanel with horizontal and vertical alignment set to LEFT and TOP, respectively. Horizontal gap will be 16 (pixels) and vertical gap will be set to 4 (pixels).

Parameters:
text - The title text of the panel. Can be set to null to indicate that there is no title.

JOptionPanel

public JOptionPanel(String text,
                    int hgap,
                    int vgap)
Create a new JOptionPanel with horizontal and vertical alignment set to LEFT and TOP, respectively.

Parameters:
text - The title text of the panel. Can be set to null to indicate that there is no title.
hgap - Horizontal gap (between titles and components).
vgap - Vertical gap.

JOptionPanel

public JOptionPanel(String text,
                    int hgap,
                    int vgap,
                    int horizAlign,
                    int vertAlign)
Create a new JOptionPanel.

Parameters:
text - The title text of the panel. Can be set to null to indicate that there is no title.
hgap - Horizontal gap (between titles and components).
vgap - Vertical gap.
horizAlign - Horizontal aligment. Can be either LEFT, RIGHT or CENTER.
vertAlign - Vertical alignment. Can be either TOP, BOTTOM or CENTER.
Method Detail

setText

public void setText(String text)
Set the option panel's title text.

Parameters:
text - The title text of the panel. Can be set to null to indicate that there is no title.

getText

public String getText()
Get the option panel's title text.

Returns:
The title text of the panel.

addOption

public void addOption(String title,
                      JComponent component)
Add the given component under the given title. The layout will be done according to the preferred dimensions of the components.

If the component's preferred width is set to Integer.MAX_VALUE, it will take up all possibly available horizontal space. If the component's preferred height is set to Integer.MAX_VALUE, it will take up all vertical space that is left. Note that there cannot be any other components underneath such a component.

Components are always shown in the order they have been added (from top to bottom).

Parameters:
title - The option's title. If it is no empty string, a colon (":") will be added automatically.
component - The component representing the option in however way.

addOption

public void addOption(String title,
                      Object text)
Add a "display only" option. the text's toString() method will be used to construct a JLabel that will be displayed. That is merely a convenience method that allows you to simply display information.

For example, you could do something like: addOption("File", "test.txt");.

Parameters:
title - The option's title. If it is no empty string, a colon (":") will be added automatically.
text - The object representing the text to show.

getOptionComponent

public Component getOptionComponent(int n)
Get the n-th option component (in the order they were added).

Parameters:
n - Number of the component to retrieve.
Returns:
The component requested.

setLayout

public void setLayout(LayoutManager mgr)
Set layout manager. Overridden so that it cannot be used anymore after initialization.

Overrides:
setLayout in class Container

SalesPoint v3.3 API