Groovy Documentation

com.wordpress.tipsforjava.swing
[Java] Class MarqueePanel

java.lang.Object
  java.awt.Component
      java.awt.Container
          javax.swing.JComponent
              javax.swing.JPanel
                  com.wordpress.tipsforjava.swing.MarqueePanel
All Implemented Interfaces:
ActionListener, AncestorListener, WindowListener

public class MarqueePanel
extends JPanel

The MarqueePanel is used to scroll components from the right edge of the panel to the left edge. Scrolling is continuous. To simulate the scrolling of text you can simply add a JLabel to the panel. Various properties control the scrolling of the components on the panel. Changes to the properties are dynamic and will take effect the next time the components are scrolled.

Authors:
Rob Camick
Darryl Burke


Field Summary
protected boolean paintChildren

private int preferredWidth

private int scrollAmount

private int scrollFrequency

protected int scrollOffset

private boolean scrollWhenFocused

protected boolean scrollingPaused

private Timer timer

private boolean wrap

private int wrapAmount

protected int wrapOffset

 
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
 
Constructor Summary
MarqueePanel()

Convenience constructor that sets both the scroll frequency and scroll amount to a value of 5.

MarqueePanel(int scrollFrequency, int scrollAmount)

Create an AnimatedIcon that will continuously cycle with the default (500ms).

 
Method Summary
void actionPerformed(ActionEvent ae)

Adjust the offset of the components on the panel so it appears that they are scrolling from right to left.

void ancestorAdded(AncestorEvent e)

Get notified when the panel is added to a Window so we can use a WindowListener to automatically start the scrolling of the components.

void ancestorMoved(AncestorEvent e)

void ancestorRemoved(AncestorEvent e)

Dimension getMinimumSize()

Dimension getPreferredSize()

int getPreferredWidth()

int getScrollAmount()

Get the scroll amount.

int getScrollFrequency()

Get the scroll frequency.

int getWrapAmount()

Get the wrap amount.

boolean isScrollWhenFocused()

Get the scroll only when visible property.

boolean isWrap()

Get the wrap property.

void paintChildren(Graphics g)

void pauseScrolling()

The components will stop scrolling but will remain visible

void resumeScrolling()

The components will resume scrolling from where scrolling was stopped.

void setPreferredWidth(int preferredWidth)

Specify the preferred width on the panel.

void setScrollAmount(int scrollAmount)

Specify the scroll amount.

void setScrollFrequency(int scrollFrequency)

Specify the scroll frequency.

void setScrollWhenFocused(boolean scrollWhenFocused)

Specify the scrolling property for unfocused windows.

void setWrap(boolean wrap)

Specify the wrapping property.

void setWrapAmount(int wrapAmount)

Specify the wrapping amount.

void startScrolling()

Start scrolling the components on the panel.

void stopScrolling()

Stop scrolling the components on the panel.

void windowActivated(WindowEvent e)

void windowClosed(WindowEvent e)

void windowClosing(WindowEvent e)

void windowDeactivated(WindowEvent e)

void windowDeiconified(WindowEvent e)

void windowIconified(WindowEvent e)

void windowOpened(WindowEvent e)

 
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
 

Field Detail

paintChildren

protected boolean paintChildren


preferredWidth

private int preferredWidth


scrollAmount

private int scrollAmount


scrollFrequency

private int scrollFrequency


scrollOffset

protected int scrollOffset


scrollWhenFocused

private boolean scrollWhenFocused


scrollingPaused

protected boolean scrollingPaused


timer

private Timer timer


wrap

private boolean wrap


wrapAmount

private int wrapAmount


wrapOffset

protected int wrapOffset


 
Constructor Detail

MarqueePanel

public MarqueePanel()
Convenience constructor that sets both the scroll frequency and scroll amount to a value of 5.


MarqueePanel

public MarqueePanel(int scrollFrequency, int scrollAmount)
Create an AnimatedIcon that will continuously cycle with the default (500ms).
Parameters:
component - the component the icon will be painted on
icons - the Icons to be painted as part of the animation


 
Method Detail

actionPerformed

public void actionPerformed(ActionEvent ae)
Adjust the offset of the components on the panel so it appears that they are scrolling from right to left.


ancestorAdded

public void ancestorAdded(AncestorEvent e)
Get notified when the panel is added to a Window so we can use a WindowListener to automatically start the scrolling of the components.


ancestorMoved

public void ancestorMoved(AncestorEvent e)


ancestorRemoved

public void ancestorRemoved(AncestorEvent e)


getMinimumSize

de
	public
public Dimension getMinimumSize()


getPreferredSize

de
	public
public Dimension getPreferredSize()


getPreferredWidth

public int getPreferredWidth()


getScrollAmount

public int getScrollAmount()
Get the scroll amount.
Returns:
the scroll amount in pixels


getScrollFrequency

public int getScrollFrequency()
Get the scroll frequency.
Returns:
the scroll frequency


getWrapAmount

public int getWrapAmount()
Get the wrap amount.
Returns:
the wrap amount value


isScrollWhenFocused

public boolean isScrollWhenFocused()
Get the scroll only when visible property.
Returns:
the scroll only when visible value


isWrap

public boolean isWrap()
Get the wrap property.
Returns:
the wrap value


paintChildren

de
	public
public void paintChildren(Graphics g)


pauseScrolling

public void pauseScrolling()
The components will stop scrolling but will remain visible


resumeScrolling

public void resumeScrolling()
The components will resume scrolling from where scrolling was stopped.


setPreferredWidth

public void setPreferredWidth(int preferredWidth)
Specify the preferred width on the panel. A value of -1 will cause the default preferred with size calculation to be used.
Parameters:
preferredWidth - preferred width of the panel in pixels


setScrollAmount

public void setScrollAmount(int scrollAmount)
Specify the scroll amount. The number of pixels to scroll every time scrolling is done.
Parameters:
scrollAmount - scroll amount in pixels


setScrollFrequency

public void setScrollFrequency(int scrollFrequency)
Specify the scroll frequency. That is the number of times scrolling should be performed every second.
Parameters:
scrollFrequency - scroll frequency


setScrollWhenFocused

public void setScrollWhenFocused(boolean scrollWhenFocused)
Specify the scrolling property for unfocused windows.
Parameters:
scrollWhenVisible - when true scrolling pauses when the window loses focus. Scrolling will continue when the window regains focus. When false scrolling is continuous unless the window is iconified.


setWrap

public void setWrap(boolean wrap)
Specify the wrapping property. Normal scrolling is such that all the text will scroll from left to right. When the last part of the text scrolls off the left edge scrolling will start again from the right edge. Therefore there is a time when the component is blank as nothing is displayed. Wrapping implies that as the end of the text scrolls off the left edge the beginning of the text will scroll in from the right edge. So the end and the start of the text is displayed at the same time.
Parameters:
wrap - when true the start of the text will scroll in from the right edge while the end of the text is still scrolling off the left edge. Otherwise the panel must be clear of text before will begin again from the right edge.


setWrapAmount

public void setWrapAmount(int wrapAmount)
Specify the wrapping amount. This specifies the space between the end of the text on the left edge and the start of the text from the right edge when wrapping is turned on.
Parameters:
wrapAmount - the amount in pixels


startScrolling

public void startScrolling()
Start scrolling the components on the panel. Components will start scrolling from the right edge towards the left edge.


stopScrolling

public void stopScrolling()
Stop scrolling the components on the panel. The conponents will be cleared from the view of the panel


windowActivated

public void windowActivated(WindowEvent e)


windowClosed

public void windowClosed(WindowEvent e)


windowClosing

public void windowClosing(WindowEvent e)


windowDeactivated

public void windowDeactivated(WindowEvent e)


windowDeiconified

public void windowDeiconified(WindowEvent e)


windowIconified

public void windowIconified(WindowEvent e)


windowOpened

public void windowOpened(WindowEvent e)


 

Groovy Documentation