Class TreeComponent


public class TreeComponent
extends JPanel

A component displaying a graphical representation of a tree. TreeComponents can be constructed quickly from TreeDrawings. The actual rendering is done by the underlying TreeDrawing. The preferred size is determined automatically, so that calls to setPrefferedSize have no effect. Because this component should not have children, no children are rendered, even if they are added. The colors of the drawing are determined by the underlying TreeDrawing, so the foreground color is unused.

Rod Howell (
See Also:
TreeDrawing, Serialized Form

Inner classes inherited from class javax.swing.JPanel
Inner classes inherited from class javax.swing.JComponent
Field Summary
static Font DEFAULT_FONT
          The default Font.
Fields inherited from class javax.swing.JComponent
Fields inherited from class java.awt.Component
Constructor Summary
TreeComponent(TreeDrawing tree)
          Constructs a new TreeComponent displaying the given TreeDrawing using the default font.
TreeComponent(TreeDrawing tree, Font fnt)
          Constructs a new TreeComponent displaying the given TreeDrawing using the given Font.
Method Summary
 Dimension getPreferredSize()
          Returns the preferred size of this component.
protected  void paintChildren(Graphics g)
          As this component should have no children, this method does nothing.
protected  void paintComponent(Graphics g)
          Paints this component on the given graphics context.
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setCursor, setLayout, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail


public static final Font DEFAULT_FONT
The default Font.
Constructor Detail


public TreeComponent(TreeDrawing tree)
              throws NullPointerException
Constructs a new TreeComponent displaying the given TreeDrawing using the default font.
NullPointerException - if tree is null


public TreeComponent(TreeDrawing tree,
                     Font fnt)
              throws NullPointerException
Constructs a new TreeComponent displaying the given TreeDrawing using the given Font.
NullPointerException - if either argument is null
Method Detail


public Dimension getPreferredSize()
Returns the preferred size of this component. This value is based solely on the underlying TreeDrawing and the component's current font. Any value set using setPreferredSize is ignored.
getPreferredSize in class JComponent
the preferred size of the drawing


protected void paintComponent(Graphics g)
Paints this component on the given graphics context.
paintComponent in class JComponent
g - The graphics context to use for painting.


protected void paintChildren(Graphics g)
As this component should have no children, this method does nothing.
paintChildren in class JComponent