Package swingtree.components
Class JScrollPanels
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JScrollPane
swingtree.UI.ScrollPane
swingtree.components.JScrollPanels
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
,ScrollPaneConstants
,StylableComponent
The
A
Instances of this store view model implementations in a view model property list so that they can dynamically be turned into views by a
Here a simple example demonstrating the usage of the
JScrollPanels
class is a container for a list of scrollable UI components
representing view models or simple data models which are dynamically turned into
views by a ViewSupplier
.
This class exists to compensate for the deficits of the JList
and JTable
components,
whose entries are not able to receive user events like for example mouse events, button clicks etc...
A
JScrollPanels
instance can arrange its entries in a vertical or horizontal manner
based on the UI.Align
parameter.
Instances of this store view model implementations in a view model property list so that they can dynamically be turned into views by a
ViewSupplier
lambda
when the list changes its state. Here a simple example demonstrating the usage of the
JScrollPanels
class
through the Swing-Tree API:
UI.scrollPanels()
.add(viewModel.entries(), entry ->
UI.panel().add(UI.button("Click me! :)"))
)
...where entries()
is a method returning a Vars
instance
which contains a list of your sub-view models.
The second parameter of the UIForAnySwing.add(sprouts.Vals, ViewSupplier)
method is a lambda
which takes a single view model from the list of view models and turns it into a view.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Instances of this are entries of thisJScrollPanels
.Nested classes/interfaces inherited from class javax.swing.JScrollPane
JScrollPane.AccessibleJScrollPane, JScrollPane.ScrollBar
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.JScrollPane
columnHeader, horizontalScrollBar, horizontalScrollBarPolicy, lowerLeft, lowerRight, rowHeader, upperLeft, upperRight, verticalScrollBar, verticalScrollBarPolicy, viewport
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
Fields inherited from interface javax.swing.ScrollPaneConstants
COLUMN_HEADER, HORIZONTAL_SCROLLBAR, HORIZONTAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_POLICY, LOWER_LEADING_CORNER, LOWER_LEFT_CORNER, LOWER_RIGHT_CORNER, LOWER_TRAILING_CORNER, ROW_HEADER, UPPER_LEADING_CORNER, UPPER_LEFT_CORNER, UPPER_RIGHT_CORNER, UPPER_TRAILING_CORNER, VERTICAL_SCROLLBAR, VERTICAL_SCROLLBAR_ALWAYS, VERTICAL_SCROLLBAR_AS_NEEDED, VERTICAL_SCROLLBAR_NEVER, VERTICAL_SCROLLBAR_POLICY, VIEWPORT
-
Method Summary
Modifier and TypeMethodDescription<M extends EntryViewModel>
voidaddAllEntries
(@Nullable String constraints, List<M> entryViewModels, ViewSupplier<M> viewSupplier) Adds multiple entries at once to thisJScrollPanels
.<M extends EntryViewModel>
voidaddEntry
(String constraints, M entryViewModel, ViewSupplier<M> viewSupplier) TheJScrollPanels
does not store components statically in the UI tree.<M extends EntryViewModel>
voidaddEntry
(M entryViewModel, ViewSupplier<M> viewSupplier) TheJScrollPanels
does not store components statically in the UI tree.<M extends EntryViewModel>
voidaddEntryAt
(int index, @Nullable String attr, M entryViewModel, ViewSupplier<M> viewSupplier) Use this to add an entry at a certain index.<T extends JComponent>
voidforEachEntry
(Class<T> type, Consumer<JScrollPanels.EntryPanel> action) Use this to iterate over all panel list entries of a certain type by supplying a type class and a consumer action.void
forEachEntry
(Consumer<JScrollPanels.EntryPanel> action) Use this to iterate over all panel list entries.int
Allows you to get the number of entries which are currently managed by thisJScrollPanels
.<T extends JComponent>
Optional<T>getSelected
(Class<T> type) Use this to find an entry component.static JScrollPanels
Constructs a newJScrollPanels
instance with the provided alignment and size.void
Use this to remove all entries.void
removeEntryAt
(int index) Use this to remove an entry at a certain index.<M extends EntryViewModel>
voidsetEntryAt
(int index, @Nullable String attr, M entryViewModel, ViewSupplier<M> viewSupplier) Use this to replace an entry at a certain index.<T extends JComponent>
voidsetSelectedFor
(Class<T> type, Predicate<T> condition) Use this to set entries as selected based on a condition lambda (predicate).Methods inherited from class swingtree.UI.ScrollPane
paint, paintChildren, setUISilently
Methods inherited from class javax.swing.JScrollPane
createHorizontalScrollBar, createVerticalScrollBar, createViewport, getAccessibleContext, getColumnHeader, getCorner, getHorizontalScrollBar, getHorizontalScrollBarPolicy, getRowHeader, getUI, getUIClassID, getVerticalScrollBar, getVerticalScrollBarPolicy, getViewport, getViewportBorder, getViewportBorderBounds, isValidateRoot, isWheelScrollingEnabled, paramString, setColumnHeader, setColumnHeaderView, setComponentOrientation, setCorner, setHorizontalScrollBar, setHorizontalScrollBarPolicy, setLayout, setRowHeader, setRowHeaderView, setUI, setVerticalScrollBar, setVerticalScrollBarPolicy, setViewport, setViewportBorder, setViewportView, setWheelScrollingEnabled, 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, paintBorder, 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, 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, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface swingtree.style.StylableComponent
paintBackground, paintForeground
-
Method Details
-
of
Constructs a newJScrollPanels
instance with the provided alignment and size.- Parameters:
align
- The alignment of the entries inside thisJScrollPanels
instance. The alignment can be eitherUI.Align.HORIZONTAL
orUI.Align.VERTICAL
.size
- The size of the entries in thisJScrollPanels
instance.- Returns:
- A new
JScrollPanels
instance.
-
getNumberOfEntries
public int getNumberOfEntries()Allows you to get the number of entries which are currently managed by thisJScrollPanels
. The number of entries is the number of view models which are currently managed by thisJScrollPanels
.- Returns:
- The number of entries which are currently managed by this
JScrollPanels
.
-
addEntry
TheJScrollPanels
does not store components statically in the UI tree. Instead, it is a hybrid of the traditional static approach and a renderer based approach (as in theJList
). The lambda passed to this method is responsible for continuously supplying a UI which fits a certain context (which defines if the entry is selected or not among other things).- Type Parameters:
M
- The type of the entry view model.- Parameters:
entryViewModel
- A view model which ought to be added.viewSupplier
- A provider lambda which ought to turn a context object into a fitting UI.
-
addEntry
public <M extends EntryViewModel> void addEntry(String constraints, M entryViewModel, ViewSupplier<M> viewSupplier) TheJScrollPanels
does not store components statically in the UI tree. Instead, it is a hybrid of the traditional static approach and a renderer based approach (as in theJList
). The view supplier lambda passed to this method is responsible for continuously supplying a UI which fits a certain context (which defines if the entry is selected or not among other things).- Type Parameters:
M
- The type of the entry view model.- Parameters:
constraints
- The constraints which ought to be applied to the entry.entryViewModel
- The entry model which ought to be added.viewSupplier
- A provider lambda which ought to turn a context object into a fitting UI.
-
addAllEntries
public <M extends EntryViewModel> void addAllEntries(@Nullable String constraints, List<M> entryViewModels, ViewSupplier<M> viewSupplier) Adds multiple entries at once to thisJScrollPanels
.- Type Parameters:
M
- The type of the entry view model.- Parameters:
constraints
- The constraints which ought to be applied to the entry.entryViewModels
- A list of entry models which ought to be added.viewSupplier
- A provider lambda which ought to turn a context object into a fitting UI.
-
removeAllEntries
public void removeAllEntries()Use this to remove all entries. -
removeEntryAt
public void removeEntryAt(int index) Use this to remove an entry at a certain index.- Parameters:
index
- The index of the entry which ought to be removed.
-
addEntryAt
public <M extends EntryViewModel> void addEntryAt(int index, @Nullable String attr, M entryViewModel, ViewSupplier<M> viewSupplier) Use this to add an entry at a certain index.- Type Parameters:
M
- The type of the entry view model.- Parameters:
index
- The index at which the entry ought to be added.attr
- The constraints which ought to be applied to the entry, may be null.entryViewModel
- The entry view model which ought to be added.viewSupplier
- The supplier which is used to create the view for the given entry view model.
-
setEntryAt
public <M extends EntryViewModel> void setEntryAt(int index, @Nullable String attr, M entryViewModel, ViewSupplier<M> viewSupplier) Use this to replace an entry at a certain index.
Note: This method will replace an existing entry at the given index.- Type Parameters:
M
- The type of the entry view model.- Parameters:
index
- The index at which the entry ought to be placed.attr
- The constraints which ought to be applied to the entry, may be null.entryViewModel
- The entry view model which ought to be added.viewSupplier
- The supplier which is used to create the view for the given entry view model.
-
getSelected
Use this to find an entry component.- Type Parameters:
T
- The component type which ought to be found.- Parameters:
type
- The component type which ought to be found.- Returns:
- The found entry panel matching the provided type class and predicate lambda.
-
forEachEntry
Use this to iterate over all panel list entries.- Parameters:
action
- The action which ought to be applied to allJScrollPanels
entries.
-
forEachEntry
public <T extends JComponent> void forEachEntry(Class<T> type, Consumer<JScrollPanels.EntryPanel> action) Use this to iterate over all panel list entries of a certain type by supplying a type class and a consumer action. Neither of the two parameters may be null!- Type Parameters:
T
- The entry value type parameter.- Parameters:
type
- The type of the entry which ought to be iterated over.action
- The action which ought to be applied to allJScrollPanels
entries of the given type.
-
setSelectedFor
Use this to set entries as selected based on a condition lambda (predicate).- Type Parameters:
T
- The type of the entry which ought to be selected.- Parameters:
type
- The type of the entry which ought to be selected.condition
- The condition which ought to be met for the entry to be selected.
-