Package ca.corbett.forms.fields
Class ListField<T>
java.lang.Object
ca.corbett.forms.fields.FormField
ca.corbett.forms.fields.ListField<T>
Wraps a JList to allow for multi-selection of some object type.
A common use case would be ListField<String> to wrap a simple
list of Strings. The underlying JList can be obtained by calling
getList(), if you need to do custom styling or whatnot on the JList.
- Since:
- swing-extras 2.3
- Author:
- scorbo2
-
Field Summary
Fields inherited from class ca.corbett.forms.fields.FormField
DEFAULT_FONT, defaultFont, extraAttributes, fieldComponent, fieldLabel, fieldValidators, helpLabel, identifier, isEnabled, isVisible, margins, validationLabel, valueChangedListeners -
Constructor Summary
ConstructorsConstructorDescriptionIf you supply a List of T, we will create and use a DefaultListModel implicitly.ListField(String label, AbstractListModel<T> listModel) If you supply a ListModel of T, we will use that instead of creating a DefaultListModel, but beware - you must populate the model beforehand. -
Method Summary
Modifier and TypeMethodDescriptionListCellRenderer<? super T> Returns the effective list cell renderer.intReturns the pixel width of each list cell.intGets the layout orientation (allowable values are JList.VERTICAL, JList.VERTICAL_WRAP, and JList.HORIZONTAL_WRAP).getList()Provides direct access to the underlying JList if needed.Provides direct access to the underlying ListModel.int[]Returns an array of selected item indexes.intGets the list selection model (allowable values are ListSelectionModel.SINGLE_SELECTION, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, and ListSelectionModel.SINGLE_INTERVAL_SELECTION).intbooleanListFields occupy more than one form row (generally - you can of course set a visibleRowCount of 1, but why would you do that).setCellRenderer(ListCellRenderer<T> renderer) You can optionally set a custom cell renderer if your list items have special display requirements.setFixedCellWidth(int width) Sets the pixel width of each list cell.setLayoutOrientation(int orientation) Sets the layout orientation (allowable values are JList.VERTICAL, JList.VERTICAL_WRAP, and JList.HORIZONTAL_WRAP).setSelectedIndex(int index) Sets a specific list index to select.setSelectedIndexes(int[] selection) Sets the selected indexes for the list.setSelectionMode(int selectionMode) Sets the list selection model (allowable values are ListSelectionModel.SINGLE_SELECTION, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, and ListSelectionModel.SINGLE_INTERVAL_SELECTION).voidsetShouldExpand(boolean should) Sets whether this list should expand horizontally to fill available form panel width.setVisibleRowCount(int count) Sets the desired visible row count.booleanOverridden here to allow optional width expansion of the list to fill the form panel's width.Methods inherited from class ca.corbett.forms.fields.FormField
addAllExtraAttributes, addFieldValidator, addValueChangedListener, clearExtraAttribute, clearExtraAttributes, clearValidationResults, equals, fireValueChangedEvent, getDefaultFont, getExtraAttribute, getFieldComponent, getFieldLabel, getHelpLabel, getHelpText, getIdentifier, getMargins, getValidationLabel, hasFieldLabel, hashCode, hasHelpLabel, hasValidationLabel, isEnabled, isValid, isVisible, preRender, removeAllFieldValidators, removeFieldValidator, removeValueChangedListener, setAllExtraAttributes, setDefaultFont, setEnabled, setExtraAttribute, setFieldLabelFont, setHelpText, setIdentifier, setMargins, setVisible, validate
-
Constructor Details
-
ListField
If you supply a List of T, we will create and use a DefaultListModel implicitly. Use the overloaded constructor if you wish to use your own ListModel instead. -
ListField
If you supply a ListModel of T, we will use that instead of creating a DefaultListModel, but beware - you must populate the model beforehand.
-
-
Method Details
-
getSelectionMode
public int getSelectionMode()Gets the list selection model (allowable values are ListSelectionModel.SINGLE_SELECTION, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, and ListSelectionModel.SINGLE_INTERVAL_SELECTION). -
setSelectionMode
Sets the list selection model (allowable values are ListSelectionModel.SINGLE_SELECTION, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, and ListSelectionModel.SINGLE_INTERVAL_SELECTION). Any other value is ignored. The default value is MULTIPLE_INTERVAL_SELECTION. -
getLayoutOrientation
public int getLayoutOrientation()Gets the layout orientation (allowable values are JList.VERTICAL, JList.VERTICAL_WRAP, and JList.HORIZONTAL_WRAP). -
setLayoutOrientation
Sets the layout orientation (allowable values are JList.VERTICAL, JList.VERTICAL_WRAP, and JList.HORIZONTAL_WRAP). Any other value is ignored. The default value is VERTICAL. -
getVisibleRowCount
public int getVisibleRowCount() -
setVisibleRowCount
Sets the desired visible row count. The default count is 4. -
getSelectedIndexes
public int[] getSelectedIndexes()Returns an array of selected item indexes. -
setSelectedIndexes
Sets the selected indexes for the list. Note: this may not do what you expect it to do depending on the current selection mode (default selection mode is MULTIPLE_INTERVAL_SELECTION, which allows multiple non-contiguous items to be selected).Passing null or an empty list will clear the selection.
-
setSelectedIndex
Sets a specific list index to select. If out of bounds, this call is ignored. -
getList
Provides direct access to the underlying JList if needed. -
getListModel
Provides direct access to the underlying ListModel. By default (unless the constructor was given something else), this will return a DefaultListModel<T> instance. -
setCellRenderer
You can optionally set a custom cell renderer if your list items have special display requirements. -
getCellRenderer
Returns the effective list cell renderer. -
getFixedCellWidth
public int getFixedCellWidth()Returns the pixel width of each list cell. A value of -1 here means the list cells will auto-size their widths based on the width of the longest item in the list. -
setFixedCellWidth
Sets the pixel width of each list cell. The default value is -1, which will set each cell's width to the width of the largest item. -
setShouldExpand
public void setShouldExpand(boolean should) Sets whether this list should expand horizontally to fill available form panel width. The default is false, meaning the list will be just wide enough to display the longest item. -
isMultiLine
public boolean isMultiLine()ListFields occupy more than one form row (generally - you can of course set a visibleRowCount of 1, but why would you do that).- Overrides:
isMultiLinein classFormField
-
shouldExpand
public boolean shouldExpand()Overridden here to allow optional width expansion of the list to fill the form panel's width. The default is false.- Overrides:
shouldExpandin classFormField
-