com.wordpress.tipsforjava.swing
[Java] Class ScrollablePanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.wordpress.tipsforjava.swing.ScrollablePanel
- All Implemented Interfaces:
- Scrollable, SwingConstants
public class ScrollablePanel
extends JPanel
A panel that implements the Scrollable interface. This class allows you
to customize the scrollable features by using newly provided setter methods
so you don't have to extend this class every time.
Scrollable amounts can be specifed as a percentage of the viewport size or
as an actual pixel value. The amount can be changed for both unit and block
scrolling for both horizontal and vertical scrollbars.
The Scrollable interface only provides a boolean value for determining whether
or not the viewport size (width or height) should be used by the scrollpane
when determining if scrollbars should be made visible. This class supports the
concept of dynamically changing this value based on the size of the viewport.
In this case the viewport size will only be used when it is larger than the
panels size. This has the effect of ensuring the viewport is always full as
components added to the panel will be size to fill the area available,
based on the rules of the applicable layout manager of course.
- Authors:
- Rob Camick
- Darryl Burke
|
Fields inherited from class JPanel
|
| WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT |
|
Fields inherited from class JComponent
|
| WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT |
|
Method Summary |
Dimension
|
getPreferredScrollableViewportSize()
|
ScrollablePanel.IncrementInfo
|
getScrollableBlockIncrement(int orientation)
Get the block IncrementInfo for the specified orientation
|
int
|
getScrollableBlockIncrement(Rectangle visible, int orientation, int direction)
|
ScrollablePanel.ScrollableSizeHint
|
getScrollableHeight()
Get the height ScrollableSizeHint enum
|
protected int
|
getScrollableIncrement(ScrollablePanel.IncrementInfo info, int distance)
|
boolean
|
getScrollableTracksViewportHeight()
|
boolean
|
getScrollableTracksViewportWidth()
|
ScrollablePanel.IncrementInfo
|
getScrollableUnitIncrement(int orientation)
Get the unit IncrementInfo for the specified orientation
|
int
|
getScrollableUnitIncrement(Rectangle visible, int orientation, int direction)
|
ScrollablePanel.ScrollableSizeHint
|
getScrollableWidth()
Get the width ScrollableSizeHint enum
|
void
|
setScrollableBlockIncrement(int orientation, ScrollablePanel.IncrementType type, int amount)
Specify the information needed to do block scrolling.
|
void
|
setScrollableBlockIncrement(int orientation, ScrollablePanel.IncrementInfo info)
Specify the information needed to do block scrolling.
|
void
|
setScrollableHeight(ScrollablePanel.ScrollableSizeHint scrollableHeight)
Set the ScrollableSizeHint enum for the height.
|
void
|
setScrollableUnitIncrement(int orientation, ScrollablePanel.IncrementType type, int amount)
Specify the information needed to do unit scrolling.
|
void
|
setScrollableUnitIncrement(int orientation, ScrollablePanel.IncrementInfo info)
Specify the information needed to do unit scrolling.
|
void
|
setScrollableWidth(ScrollablePanel.ScrollableSizeHint scrollableWidth)
Set the ScrollableSizeHint enum for the width.
|
ScrollablePanel
|
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
ScrollablePanel
|
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
ScrollablePanel[]
|
values()
Returns an array containing the constants of this enum type, in the order they are declared.
|
ScrollablePanel[]
|
values()
Returns an array containing the constants of this enum type, in the order they are declared.
|
|
Methods inherited from class JPanel
|
| getAccessibleContext, setUI, updateUI, getUIClassID, getUI, contains, getLocation, print, getSize, isOpaque, enable, disable, update, getY, getX, getInsets, getInsets, setFont, getPreferredSize, getMinimumSize, getMaximumSize, getAlignmentX, getAlignmentY, paint, getListeners, addNotify, removeNotify, setFocusTraversalKeys, requestFocus, requestFocus, firePropertyChange, firePropertyChange, firePropertyChange, setEnabled, isDoubleBuffered, setVisible, setForeground, setBackground, getBounds, reshape, getWidth, getHeight, setPreferredSize, setMinimumSize, setMaximumSize, getBaseline, getBaselineResizeBehavior, getGraphics, getFontMetrics, repaint, repaint, printAll, requestFocusInWindow, addAncestorListener, setInheritsPopupMenu, getInheritsPopupMenu, setComponentPopupMenu, getComponentPopupMenu, isPaintingTile, isPaintingForPrint, isManagingFocus, setNextFocusableComponent, getNextFocusableComponent, setRequestFocusEnabled, isRequestFocusEnabled, grabFocus, setVerifyInputWhenFocusTarget, getVerifyInputWhenFocusTarget, setBorder, getBorder, setAlignmentY, setAlignmentX, setInputVerifier, getInputVerifier, setDebugGraphicsOptions, getDebugGraphicsOptions, registerKeyboardAction, registerKeyboardAction, unregisterKeyboardAction, getRegisteredKeyStrokes, getConditionForKeyStroke, getActionForKeyStroke, resetKeyboardActions, setInputMap, getInputMap, getInputMap, setActionMap, getActionMap, requestDefaultFocus, getDefaultLocale, setDefaultLocale, setToolTipText, getToolTipText, getToolTipText, getToolTipLocation, getPopupLocation, createToolTip, scrollRectToVisible, setAutoscrolls, getAutoscrolls, setTransferHandler, getTransferHandler, getClientProperty, putClientProperty, isLightweightComponent, setOpaque, computeVisibleRect, getVisibleRect, addVetoableChangeListener, removeVetoableChangeListener, getVetoableChangeListeners, getTopLevelAncestor, removeAncestorListener, getAncestorListeners, revalidate, isValidateRoot, isOptimizedDrawingEnabled, paintImmediately, paintImmediately, setDoubleBuffered, getRootPane, add, add, add, add, add, remove, remove, list, list, removeAll, getComponent, invalidate, validate, getComponentCount, countComponents, getComponents, insets, setComponentZOrder, getComponentZOrder, getLayout, setLayout, doLayout, layout, preferredSize, minimumSize, paintComponents, printComponents, addContainerListener, removeContainerListener, getContainerListeners, deliverEvent, getComponentAt, getComponentAt, locate, getMousePosition, findComponentAt, findComponentAt, isAncestorOf, getFocusTraversalKeys, areFocusTraversalKeysSet, isFocusCycleRoot, isFocusCycleRoot, transferFocusBackward, setFocusTraversalPolicy, getFocusTraversalPolicy, isFocusTraversalPolicySet, setFocusCycleRoot, setFocusTraversalPolicyProvider, isFocusTraversalPolicyProvider, transferFocusDownCycle, applyComponentOrientation, addPropertyChangeListener, addPropertyChangeListener, add, toString, getName, contains, size, getParent, getLocation, remove, setName, list, list, list, getSize, resize, resize, setSize, setSize, enable, location, isValid, setLocale, action, getMousePosition, getGraphicsConfiguration, dispatchEvent, isVisible, isEnabled, isDisplayable, isFocusable, getTreeLock, isLightweight, getPeer, isFocusOwner, transferFocus, getFont, isPreferredSizeSet, isMinimumSizeSet, isMaximumSizeSet, isShowing, handleEvent, postEvent, getFocusCycleRootAncestor, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, setDropTarget, getDropTarget, getToolkit, enableInputMethods, show, show, hide, getForeground, isForegroundSet, getBackground, isBackgroundSet, isFontSet, getLocale, getColorModel, getLocationOnScreen, setLocation, setLocation, move, getBounds, bounds, setBounds, setBounds, setCursor, getCursor, isCursorSet, paintAll, repaint, repaint, repaint, imageUpdate, createImage, createImage, createVolatileImage, createVolatileImage, prepareImage, prepareImage, checkImage, checkImage, setIgnoreRepaint, getIgnoreRepaint, inside, addComponentListener, removeComponentListener, getComponentListeners, addFocusListener, removeFocusListener, getFocusListeners, addHierarchyListener, removeHierarchyListener, getHierarchyListeners, addHierarchyBoundsListener, removeHierarchyBoundsListener, getHierarchyBoundsListeners, addKeyListener, removeKeyListener, getKeyListeners, addMouseListener, removeMouseListener, getMouseListeners, addMouseMotionListener, removeMouseMotionListener, getMouseMotionListeners, addMouseWheelListener, removeMouseWheelListener, getMouseWheelListeners, addInputMethodListener, removeInputMethodListener, getInputMethodListeners, getInputMethodRequests, getInputContext, mouseDown, mouseDrag, mouseUp, mouseMove, mouseEnter, mouseExit, keyDown, keyUp, gotFocus, lostFocus, isFocusTraversable, setFocusable, setFocusTraversalKeysEnabled, getFocusTraversalKeysEnabled, nextFocus, transferFocusUpCycle, hasFocus, removePropertyChangeListener, removePropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, setComponentOrientation, getComponentOrientation, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll |
|
Methods inherited from class JComponent
|
| contains, getLocation, print, getSize, isOpaque, enable, disable, update, getY, getX, getInsets, getInsets, setFont, getPreferredSize, getMinimumSize, getMaximumSize, getAlignmentX, getAlignmentY, paint, getListeners, addNotify, removeNotify, setFocusTraversalKeys, requestFocus, requestFocus, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, setEnabled, isDoubleBuffered, setVisible, setForeground, setBackground, getBounds, reshape, getWidth, getHeight, setPreferredSize, setMinimumSize, setMaximumSize, getBaseline, getBaselineResizeBehavior, getGraphics, getFontMetrics, repaint, repaint, printAll, requestFocusInWindow, updateUI, getUIClassID, addAncestorListener, setInheritsPopupMenu, getInheritsPopupMenu, setComponentPopupMenu, getComponentPopupMenu, isPaintingTile, isPaintingForPrint, isManagingFocus, setNextFocusableComponent, getNextFocusableComponent, setRequestFocusEnabled, isRequestFocusEnabled, grabFocus, setVerifyInputWhenFocusTarget, getVerifyInputWhenFocusTarget, setBorder, getBorder, setAlignmentY, setAlignmentX, setInputVerifier, getInputVerifier, setDebugGraphicsOptions, getDebugGraphicsOptions, registerKeyboardAction, registerKeyboardAction, unregisterKeyboardAction, getRegisteredKeyStrokes, getConditionForKeyStroke, getActionForKeyStroke, resetKeyboardActions, setInputMap, getInputMap, getInputMap, setActionMap, getActionMap, requestDefaultFocus, getDefaultLocale, setDefaultLocale, setToolTipText, getToolTipText, getToolTipText, getToolTipLocation, getPopupLocation, createToolTip, scrollRectToVisible, setAutoscrolls, getAutoscrolls, setTransferHandler, getTransferHandler, getClientProperty, putClientProperty, isLightweightComponent, setOpaque, computeVisibleRect, getVisibleRect, addVetoableChangeListener, removeVetoableChangeListener, getVetoableChangeListeners, getTopLevelAncestor, removeAncestorListener, getAncestorListeners, revalidate, isValidateRoot, isOptimizedDrawingEnabled, paintImmediately, paintImmediately, setDoubleBuffered, getRootPane, add, add, add, add, add, remove, remove, list, list, removeAll, getComponent, invalidate, validate, getComponentCount, countComponents, getComponents, insets, setComponentZOrder, getComponentZOrder, getLayout, setLayout, doLayout, layout, preferredSize, minimumSize, paintComponents, printComponents, addContainerListener, removeContainerListener, getContainerListeners, deliverEvent, getComponentAt, getComponentAt, locate, getMousePosition, findComponentAt, findComponentAt, isAncestorOf, getFocusTraversalKeys, areFocusTraversalKeysSet, isFocusCycleRoot, isFocusCycleRoot, transferFocusBackward, setFocusTraversalPolicy, getFocusTraversalPolicy, isFocusTraversalPolicySet, setFocusCycleRoot, setFocusTraversalPolicyProvider, isFocusTraversalPolicyProvider, transferFocusDownCycle, applyComponentOrientation, addPropertyChangeListener, addPropertyChangeListener, add, toString, getName, contains, size, getParent, getLocation, remove, setName, list, list, list, getSize, resize, resize, setSize, setSize, enable, location, isValid, setLocale, action, getMousePosition, getGraphicsConfiguration, dispatchEvent, isVisible, isEnabled, isDisplayable, isFocusable, getTreeLock, isLightweight, getPeer, isFocusOwner, transferFocus, getFont, isPreferredSizeSet, isMinimumSizeSet, isMaximumSizeSet, isShowing, handleEvent, postEvent, getFocusCycleRootAncestor, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, setDropTarget, getDropTarget, getToolkit, enableInputMethods, show, show, hide, getForeground, isForegroundSet, getBackground, isBackgroundSet, isFontSet, getLocale, getColorModel, getLocationOnScreen, setLocation, setLocation, move, getBounds, bounds, setBounds, setBounds, setCursor, getCursor, isCursorSet, paintAll, repaint, repaint, repaint, imageUpdate, createImage, createImage, createVolatileImage, createVolatileImage, prepareImage, prepareImage, checkImage, checkImage, setIgnoreRepaint, getIgnoreRepaint, inside, addComponentListener, removeComponentListener, getComponentListeners, addFocusListener, removeFocusListener, getFocusListeners, addHierarchyListener, removeHierarchyListener, getHierarchyListeners, addHierarchyBoundsListener, removeHierarchyBoundsListener, getHierarchyBoundsListeners, addKeyListener, removeKeyListener, getKeyListeners, addMouseListener, removeMouseListener, getMouseListeners, addMouseMotionListener, removeMouseMotionListener, getMouseMotionListeners, addMouseWheelListener, removeMouseWheelListener, getMouseWheelListeners, addInputMethodListener, removeInputMethodListener, getInputMethodListeners, getInputMethodRequests, getInputContext, mouseDown, mouseDrag, mouseUp, mouseMove, mouseEnter, mouseExit, keyDown, keyUp, gotFocus, lostFocus, isFocusTraversable, setFocusable, setFocusTraversalKeysEnabled, getFocusTraversalKeysEnabled, nextFocus, transferFocusUpCycle, hasFocus, removePropertyChangeListener, removePropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, setComponentOrientation, getComponentOrientation, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll |
horizontalBlock
private ScrollablePanel.IncrementInfo horizontalBlock
-
horizontalUnit
private ScrollablePanel.IncrementInfo horizontalUnit
-
scrollableHeight
private ScrollablePanel.ScrollableSizeHint scrollableHeight
- A panel that implements the Scrollable interface. This class allows you
to customize the scrollable features by using newly provided setter methods
so you don't have to extend this class every time.
Scrollable amounts can be specifed as a percentage of the viewport size or
as an actual pixel value. The amount can be changed for both unit and block
scrolling for both horizontal and vertical scrollbars.
The Scrollable interface only provides a boolean value for determining whether
or not the viewport size (width or height) should be used by the scrollpane
when determining if scrollbars should be made visible. This class supports the
concept of dynamically changing this value based on the size of the viewport.
In this case the viewport size will only be used when it is larger than the
panels size. This has the effect of ensuring the viewport is always full as
components added to the panel will be size to fill the area available,
based on the rules of the applicable layout manager of course.
- Authors:
- Rob Camick
- Darryl Burke
scrollableWidth
private ScrollablePanel.ScrollableSizeHint scrollableWidth
-
verticalBlock
private ScrollablePanel.IncrementInfo verticalBlock
-
verticalUnit
private ScrollablePanel.IncrementInfo verticalUnit
-
ScrollablePanel
public ScrollablePanel()
- Default constructor that uses a FlowLayout
ScrollablePanel
public ScrollablePanel(LayoutManager layout)
- Constuctor for specifying the LayoutManager of the panel.
- Parameters:
layout - the LayountManger for the panel
getPreferredScrollableViewportSize
public Dimension getPreferredScrollableViewportSize()
-
getScrollableBlockIncrement
public ScrollablePanel.IncrementInfo getScrollableBlockIncrement(int orientation)
- Get the block IncrementInfo for the specified orientation
- Returns:
- the block IncrementInfo for the specified orientation
getScrollableBlockIncrement
public int getScrollableBlockIncrement(Rectangle visible, int orientation, int direction)
-
getScrollableHeight
public ScrollablePanel.ScrollableSizeHint getScrollableHeight()
- Get the height ScrollableSizeHint enum
- Returns:
- the ScrollableSizeHint enum for the height
getScrollableIncrement
protected int getScrollableIncrement(ScrollablePanel.IncrementInfo info, int distance)
-
getScrollableTracksViewportHeight
public boolean getScrollableTracksViewportHeight()
-
getScrollableTracksViewportWidth
public boolean getScrollableTracksViewportWidth()
-
getScrollableUnitIncrement
public ScrollablePanel.IncrementInfo getScrollableUnitIncrement(int orientation)
- Get the unit IncrementInfo for the specified orientation
- Returns:
- the unit IncrementInfo for the specified orientation
getScrollableUnitIncrement
public int getScrollableUnitIncrement(Rectangle visible, int orientation, int direction)
-
getScrollableWidth
public ScrollablePanel.ScrollableSizeHint getScrollableWidth()
- Get the width ScrollableSizeHint enum
- Returns:
- the ScrollableSizeHint enum for the width
setScrollableBlockIncrement
public void setScrollableBlockIncrement(int orientation, ScrollablePanel.IncrementType type, int amount)
- Specify the information needed to do block scrolling.
- paran:
- type specify how the amount parameter in the calculation of
the scrollable amount. Valid values are:
IncrementType.PERCENT - treat the amount as a % of the viewport size
IncrementType.PIXEL - treat the amount as the scrollable amount
- Parameters:
orientation - specify the scrolling orientation. Must be either:
SwingContants.HORIZONTAL or SwingContants.VERTICAL.amount - a value used with the IncrementType to determine the
scrollable amount
setScrollableBlockIncrement
public void setScrollableBlockIncrement(int orientation, ScrollablePanel.IncrementInfo info)
- Specify the information needed to do block scrolling.
- Parameters:
orientation - specify the scrolling orientation. Must be either:
SwingContants.HORIZONTAL or SwingContants.VERTICAL.info - An IncrementInfo object containing information of how to
calculate the scrollable amount.
setScrollableHeight
public void setScrollableHeight(ScrollablePanel.ScrollableSizeHint scrollableHeight)
- Set the ScrollableSizeHint enum for the height. The enum is used to
determine the boolean value that is returned by the
getScrollableTracksViewportHeight() method. The valid values are:
ScrollableSizeHint.NONE - return "false", which causes the height
of the panel to be used when laying out the children
ScrollableSizeHint.FIT - return "true", which causes the height of
the viewport to be used when laying out the children
ScrollableSizeHint.STRETCH - return "true" when the viewport height
is greater than the height of the panel, "false" otherwise.
- Parameters:
scrollableHeight - as represented by the ScrollableSizeHint enum.
setScrollableUnitIncrement
public void setScrollableUnitIncrement(int orientation, ScrollablePanel.IncrementType type, int amount)
- Specify the information needed to do unit scrolling.
- paran:
- type specify how the amount parameter in the calculation of
the scrollable amount. Valid values are:
IncrementType.PERCENT - treat the amount as a % of the viewport size
IncrementType.PIXEL - treat the amount as the scrollable amount
- Parameters:
orientation - specify the scrolling orientation. Must be either:
SwingContants.HORIZONTAL or SwingContants.VERTICAL.amount - a value used with the IncrementType to determine the
scrollable amount
setScrollableUnitIncrement
public void setScrollableUnitIncrement(int orientation, ScrollablePanel.IncrementInfo info)
- Specify the information needed to do unit scrolling.
- Parameters:
orientation - specify the scrolling orientation. Must be either:
SwingContants.HORIZONTAL or SwingContants.VERTICAL.info - An IncrementInfo object containing information of how to
calculate the scrollable amount.
setScrollableWidth
public void setScrollableWidth(ScrollablePanel.ScrollableSizeHint scrollableWidth)
- Set the ScrollableSizeHint enum for the width. The enum is used to
determine the boolean value that is returned by the
getScrollableTracksViewportWidth() method. The valid values are:
ScrollableSizeHint.NONE - return "false", which causes the width
of the panel to be used when laying out the children
ScrollableSizeHint.FIT - return "true", which causes the width of
the viewport to be used when laying out the children
ScrollableSizeHint.STRETCH - return "true" when the viewport width
is greater than the width of the panel, "false" otherwise.
- Parameters:
scrollableWidth - as represented by the ScrollableSizeHint enum.
valueOf
ScrollablePanel valueOf(String name)
- Returns the enum constant of this type with the specified name.
valueOf
ScrollablePanel valueOf(String name)
- Returns the enum constant of this type with the specified name.
values
ScrollablePanel[] values()
- Returns an array containing the constants of this enum type, in the order they are declared.
values
ScrollablePanel[] values()
- Returns an array containing the constants of this enum type, in the order they are declared.
Groovy Documentation