Class TreeComponent

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

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.
Author:
Rod Howell (rhowell@ksu.edu)
See Also:
  • Field Details

    • DEFAULT_FONT

      public static final Font DEFAULT_FONT
      The default Font.
  • Constructor Details

    • TreeComponent

      public TreeComponent(TreeDrawing tree) throws NullPointerException
      Constructs a new TreeComponent displaying the given TreeDrawing using the default font.
      Parameters:
      tree - the drawing to be displayed
      Throws:
      NullPointerException - if tree is null
    • TreeComponent

      public TreeComponent(TreeDrawing tree, Font fnt) throws NullPointerException
      Constructs a new TreeComponent displaying the given TreeDrawing using the given Font.
      Parameters:
      tree - the drawing to be displayed
      fnt - the font to use
      Throws:
      NullPointerException - if either argument is null
  • Method Details

    • getPreferredSize

      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.
      Overrides:
      getPreferredSize in class JComponent
      Returns:
      the preferred size of the drawing
    • paintComponent

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

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