Package nl.colorize.util.swing
Class FormPanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
nl.colorize.util.swing.FormPanel
- All Implemented Interfaces:
ImageObserver
,LayoutManager
,MenuContainer
,Serializable
,Accessible
Panel that arranges components in a 2 x N grid. This layout is similar to how
most web pages arrange their forms, and provides a good template layout for
creating property panels and such. Some aspects of the form's appearance depend
on the platform's user interface conventions.
Cells in the label column will get a certain percentage of the total available
width, with all components in the value column sharing the remaining space.
Components that are not marked as being a row (i.e. that were not added using
one of the addRow(...)
methods, will take up the entire row.
This class uses a custom LayoutManager
to achieve the desired effect,
changing the layout manager will mean these capabilities are lost.
- See Also:
-
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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
ConstructorDescriptionCreates aFormPanel
with alignments and margins conforming to the user interface conventions for the underlying platform. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBoldRow
(String labelText) Adds a row that only consists of a single text label with a bold font that spans the entire width of the row.void
addEllipsesRow
(Supplier<String> labelProvider, Runnable callback) Adds a row with a text label and an ellipsis button (...) that when invoked will trigger a callback action, which will in turn update the label.void
Adds an empty row that takes vertical space, but does not have any components in it.void
addLayoutComponent
(String name, Component component) void
addRow()
Deprecated.void
Adds a row that only consists of a single text label that spans the entire width of the row.void
Adds a row that consists of a text label and a value label.void
Adds a row that consists of a text label, a value label, and a button.void
Adds a row that consists of a text label and a button.void
addRow
(String label, JComponent valueCell) Adds a row that consists of the specified text label and value cells.void
addRow
(String label, JComponent first, JComponent second) Adds a row that consists of a text label in the left column, and two components in the right column.void
addRow
(String label, JRadioButton... choices) Adds a row that consists of a text label in and a number of radio buttons.void
Adds a row that consists of a text label and a slider.void
Adds a row that consists of a single button.void
addRow
(JComponent component) Adds a row that contains a single component that will use the entire available width.void
addRow
(JComponent component, int height) Adds a row that contains a single component that will use the entire available width and the specified height.void
addRow
(JComponent labelCell, JComponent valueCell) Adda a row that consists of the specified label and value cells.void
addSpacerRow
(int height) Adds an empty row that takes the specified amount of vertical space.int
void
layoutContainer
(Container parent) minimumLayoutSize
(Container parent) void
Updates the form's preferred height based on the minimum height that fits all rows.preferredLayoutSize
(Container parent) void
removeLayoutComponent
(Component component) void
setHorizontalMargin
(int horizontalMargin) void
setRightAlignLabels
(boolean rightAlignLabels) void
setVerticalMargin
(int verticalMargin) 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, 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, 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 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, setLayout, 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, 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
-
FormPanel
public FormPanel()Creates aFormPanel
with alignments and margins conforming to the user interface conventions for the underlying platform.
-
-
Method Details
-
addRow
Deprecated.Use the more clearly namedaddEmptyRow()
instead.Adds an empty row. -
addRow
Adds a row that contains a single component that will use the entire available width. -
addRow
Adds a row that contains a single component that will use the entire available width and the specified height. -
addRow
Adda a row that consists of the specified label and value cells. -
addRow
Adds a row that consists of the specified text label and value cells. -
addRow
Adds a row that consists of a text label and a value label. -
addRow
Adds a row that consists of a text label in and a number of radio buttons. -
addRow
Adds a row that consists of a text label and a slider.- Parameters:
addValueLabel
- When true, show the (numerical) slider value in a label displayed behind the slider.
-
addRow
Adds a row that consists of a text label and a button. Clicking the button will perform an action that results in the text label being updated.- Parameters:
action
- Callback action invoked when the button is clicked. This should return the new text to be used for the text label.
-
addRow
public void addRow(String label, String initialValueLabel, String actionButtonText, Callable<String> action) Adds a row that consists of a text label, a value label, and a button. Clicking the button will perform an action that results in the value label being updated.- Parameters:
action
- Callback action invoked when the button is clicked. This should return the new text to be used for the value label.
-
addRow
Adds a row that consists of a single button.- Parameters:
fullWidth
- If true, the button will span the full width of the row. If false, it will only take its preferred width.
-
addRow
Adds a row that only consists of a single text label that spans the entire width of the row. -
addRow
Adds a row that consists of a text label in the left column, and two components in the right column. The latter will be displayed using their native/preferred width to share the available space within the column. -
addEllipsesRow
Adds a row with a text label and an ellipsis button (...) that when invoked will trigger a callback action, which will in turn update the label. -
addBoldRow
Adds a row that only consists of a single text label with a bold font that spans the entire width of the row. -
addEmptyRow
public void addEmptyRow()Adds an empty row that takes vertical space, but does not have any components in it. -
addSpacerRow
public void addSpacerRow(int height) Adds an empty row that takes the specified amount of vertical space. -
packFormHeight
public void packFormHeight()Updates the form's preferred height based on the minimum height that fits all rows. The form's height is automatically updated every time a row is added using one of theaddRow(...)
methods, but can also be called manually if one of the row components has changed and the form's layout needs to be updated. -
setHorizontalMargin
public void setHorizontalMargin(int horizontalMargin) -
setVerticalMargin
public void setVerticalMargin(int verticalMargin) -
getVerticalMargin
public int getVerticalMargin() -
setRightAlignLabels
public void setRightAlignLabels(boolean rightAlignLabels) -
addLayoutComponent
- Specified by:
addLayoutComponent
in interfaceLayoutManager
-
removeLayoutComponent
- Specified by:
removeLayoutComponent
in interfaceLayoutManager
-
preferredLayoutSize
- Specified by:
preferredLayoutSize
in interfaceLayoutManager
-
minimumLayoutSize
- Specified by:
minimumLayoutSize
in interfaceLayoutManager
-
layoutContainer
- Specified by:
layoutContainer
in interfaceLayoutManager
-
addEmptyRow()
instead.