Class JTree

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, FieldReconciler.Reconcilable

public class JTree extends JComponent implements Scrollable, Accessible, FieldReconciler.Reconcilable
Emulator for JTree — a thin delegating shell over its SJTree peer; R_leaf_peer_lockdown-locked-down (JDK leaf — private peer ctor). Implements Scrollable and Accessible to match the JDK interface set.
See Also:
  • Field Details

    • CELL_RENDERER_PROPERTY

      public static final String CELL_RENDERER_PROPERTY
      See Also:
    • TREE_MODEL_PROPERTY

      public static final String TREE_MODEL_PROPERTY
      See Also:
    • ROOT_VISIBLE_PROPERTY

      public static final String ROOT_VISIBLE_PROPERTY
      See Also:
    • SHOWS_ROOT_HANDLES_PROPERTY

      public static final String SHOWS_ROOT_HANDLES_PROPERTY
      See Also:
    • ROW_HEIGHT_PROPERTY

      public static final String ROW_HEIGHT_PROPERTY
      See Also:
    • CELL_EDITOR_PROPERTY

      public static final String CELL_EDITOR_PROPERTY
      See Also:
    • EDITABLE_PROPERTY

      public static final String EDITABLE_PROPERTY
      See Also:
    • LARGE_MODEL_PROPERTY

      public static final String LARGE_MODEL_PROPERTY
      See Also:
    • SELECTION_MODEL_PROPERTY

      public static final String SELECTION_MODEL_PROPERTY
      See Also:
    • VISIBLE_ROW_COUNT_PROPERTY

      public static final String VISIBLE_ROW_COUNT_PROPERTY
      See Also:
    • INVOKES_STOP_CELL_EDITING_PROPERTY

      public static final String INVOKES_STOP_CELL_EDITING_PROPERTY
      See Also:
    • SCROLLS_ON_EXPAND_PROPERTY

      public static final String SCROLLS_ON_EXPAND_PROPERTY
      See Also:
    • TOGGLE_CLICK_COUNT_PROPERTY

      public static final String TOGGLE_CLICK_COUNT_PROPERTY
      See Also:
    • LEAD_SELECTION_PATH_PROPERTY

      public static final String LEAD_SELECTION_PATH_PROPERTY
      See Also:
    • ANCHOR_SELECTION_PATH_PROPERTY

      public static final String ANCHOR_SELECTION_PATH_PROPERTY
      See Also:
    • EXPANDS_SELECTED_PATHS_PROPERTY

      public static final String EXPANDS_SELECTED_PATHS_PROPERTY
      See Also:
    • cellRenderer

      protected TreeCellRenderer cellRenderer
      Currently installed JDK-shaped cell renderer; seeded with DefaultTreeCellRenderer.
    • treeModelListener

      protected transient TreeModelListener treeModelListener
      The JDK hook's listener, subscribed to treeModel; keeps expandedState in step with the model.
    • treeModel

      protected transient TreeModel treeModel
    • selectionModel

      protected transient TreeSelectionModel selectionModel
    • rootVisible

      protected boolean rootVisible
    • showsRootHandles

      protected boolean showsRootHandles
    • rowHeight

      protected int rowHeight
    • scrollsOnExpand

      protected boolean scrollsOnExpand
    • toggleClickCount

      protected int toggleClickCount
    • visibleRowCount

      protected int visibleRowCount
    • editable

      protected boolean editable
    • invokesStopCellEditing

      protected boolean invokesStopCellEditing
    • largeModel

      protected boolean largeModel
    • cellEditor

      protected TreeCellEditor cellEditor
  • Constructor Details

    • JTree

      public JTree()
      JDK shape: shows the sample demo model.
    • JTree

      public JTree(Object[] value)
    • JTree

      public JTree(Vector<?> value)
    • JTree

      public JTree(Hashtable<?,?> value)
    • JTree

      public JTree(TreeNode root)
    • JTree

      public JTree(TreeNode root, boolean asksAllowsChildren)
    • JTree

      public JTree(TreeModel newModel)
      The root ctor, and the only one naming the peer: R_leaf_peer_lockdown lock-down (JDK leaf — no protected (Component) ctor).
      Throws:
      NullPointerException - if newModel is null, which the JDK accepts — the surrogate needs a model
  • Method Details

    • reconcileFields

      public final void reconcileFields()
      D_field_write_reconcile repair hook — see JSlider.reconcileFields().
      Specified by:
      reconcileFields in interface FieldReconciler.Reconcilable
    • getDefaultTreeModel

      protected static TreeModel getDefaultTreeModel()
      JDK's sample model (javax.swing.JTree.getDefaultTreeModel()): the "JTree" root with colors / sports / food children.
    • createTreeModel

      protected static TreeModel createTreeModel(Object value)
      JDK's createTreeModel shape: wrap the entries under a synthetic "root" node (hidden by the calling ctor's setRootVisible(false)). Nested arrays / Vectors / Hashtables recurse — the eager equivalent of the JDK's lazy DynamicUtilTreeNode expansion (R_best_effort_behaviour).
    • getModel

      public TreeModel getModel()
    • setModel

      public void setModel(TreeModel newModel)
    • getCellRenderer

      public TreeCellRenderer getCellRenderer()
    • setCellRenderer

      public void setCellRenderer(TreeCellRenderer x)
    • convertValueToText

      public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
      The JDK-overridable node-to-text formatting hook the default renderer's text flows through. Subclasses overriding this (a common migration pattern) take effect on every rendered cell.
    • isRootVisible

      public boolean isRootVisible()
    • setRootVisible

      public void setRootVisible(boolean rootVisible)
    • getSelectionModel

      public TreeSelectionModel getSelectionModel()
    • setSelectionModel

      public void setSelectionModel(TreeSelectionModel selectionModel)
    • setSelectionPath

      public void setSelectionPath(TreePath path)
    • setSelectionPaths

      public void setSelectionPaths(TreePath[] paths)
    • addSelectionPath

      public void addSelectionPath(TreePath path)
    • addSelectionPaths

      public void addSelectionPaths(TreePath[] paths)
    • removeSelectionPath

      public void removeSelectionPath(TreePath path)
    • removeSelectionPaths

      public void removeSelectionPaths(TreePath[] paths)
    • getSelectionPath

      public TreePath getSelectionPath()
    • getSelectionPaths

      public TreePath[] getSelectionPaths()
    • getSelectionCount

      public int getSelectionCount()
    • isPathSelected

      public boolean isPathSelected(TreePath path)
    • isSelectionEmpty

      public boolean isSelectionEmpty()
    • clearSelection

      public void clearSelection()
    • getLastSelectedPathComponent

      public Object getLastSelectedPathComponent()
    • getLeadSelectionPath

      public TreePath getLeadSelectionPath()
      Returns:
      this tree's own lead path, not the selection model's — they are two stores and the JDK keeps them apart: measured on JDK 25, setLeadSelectionPath(pathNotInTheTree) moves this one and leaves the model's where it was. What holds them in step on an ordinary selection change is syncAnchorAndLeadFromSelection().
    • setSelectionRow

      public void setSelectionRow(int row)
    • setSelectionRows

      public void setSelectionRows(int[] rows)
    • addSelectionRow

      public void addSelectionRow(int row)
    • addSelectionRows

      public void addSelectionRows(int[] rows)
    • removeSelectionRow

      public void removeSelectionRow(int row)
    • removeSelectionRows

      public void removeSelectionRows(int[] rows)
    • setSelectionInterval

      public void setSelectionInterval(int index0, int index1)
    • addSelectionInterval

      public void addSelectionInterval(int index0, int index1)
    • removeSelectionInterval

      public void removeSelectionInterval(int index0, int index1)
    • getSelectionRows

      public int[] getSelectionRows()
      Resolved through the installed RowMapper (the visible-node walk).
    • getMinSelectionRow

      public int getMinSelectionRow()
    • getMaxSelectionRow

      public int getMaxSelectionRow()
    • getLeadSelectionRow

      public int getLeadSelectionRow()
    • isRowSelected

      public boolean isRowSelected(int row)
    • addTreeSelectionListener

      public void addTreeSelectionListener(TreeSelectionListener tsl)
    • removeTreeSelectionListener

      public void removeTreeSelectionListener(TreeSelectionListener tsl)
    • getTreeSelectionListeners

      public TreeSelectionListener[] getTreeSelectionListeners()
    • fireValueChanged

      protected void fireValueChanged(TreeSelectionEvent e)
    • expandPath

      public void expandPath(TreePath path)
    • collapsePath

      public void collapsePath(TreePath path)
    • expandRow

      public void expandRow(int row)
    • collapseRow

      public void collapseRow(int row)
    • isExpanded

      public boolean isExpanded(TreePath path)
      Whether path and every one of its ancestors is expanded.
    • isExpanded

      public boolean isExpanded(int row)
      The node at row's own expanded flag; its ancestors are expanded, or it would have no row.
    • isCollapsed

      public boolean isCollapsed(TreePath path)
    • isCollapsed

      public boolean isCollapsed(int row)
    • hasBeenExpanded

      public boolean hasBeenExpanded(TreePath path)
      Whether path was ever expanded or collapsed, as the JDK's toggled-paths table records.
    • makeVisible

      public void makeVisible(TreePath path)
    • isVisible

      public boolean isVisible(TreePath path)
    • scrollPathToVisible

      public void scrollPathToVisible(TreePath path)
      Expands ancestors (firing TreeExpansionEvents) then scrolls, when the path is then visible; R_layouts_close_enough — no pixel guarantee.
    • scrollRowToVisible

      public void scrollRowToVisible(int row)
    • getExpandedDescendants

      public Enumeration<TreePath> getExpandedDescendants(TreePath parent)
      The expanded, visible descendants of parent, excluding parent; empty when there are none, null when parent is not expanded. Read from the toggled-paths table, so in no particular order, as in the JDK.
    • setExpandedState

      protected void setExpandedState(TreePath path, boolean state)
      The JDK's expansion engine. Expands every collapsed ancestor first, each vetoable by a TreeWillExpandListener and announced to the TreeExpansionListeners, then expands or collapses path itself the same way; a veto stops the walk where it lands. Collapsing moves a selection inside the collapsed subtree onto path. Every change is flushed to the peer.
    • clearToggledPaths

      protected void clearToggledPaths()
      Clears the toggled-paths table; fires nothing, as in the JDK.
    • removeDescendantToggledPaths

      protected void removeDescendantToggledPaths(Enumeration<TreePath> toRemove)
      Removes every toggled path under each of toRemove, the paths themselves included.
    • getDescendantToggledPaths

      protected Enumeration<TreePath> getDescendantToggledPaths(TreePath parent)
      The toggled paths under parent, parent included.
    • removeDescendantSelectedPaths

      protected boolean removeDescendantSelectedPaths(TreePath path, boolean includePath)
      Removes the selected paths under path; true if there were any.
    • createTreeModelListener

      protected TreeModelListener createTreeModelListener()
      The JTree.TreeModelHandler the JDK subscribes to the model; an override may return its own, or null for none.
    • addTreeExpansionListener

      public void addTreeExpansionListener(TreeExpansionListener tel)
    • removeTreeExpansionListener

      public void removeTreeExpansionListener(TreeExpansionListener tel)
    • getTreeExpansionListeners

      public TreeExpansionListener[] getTreeExpansionListeners()
    • fireTreeExpanded

      public void fireTreeExpanded(TreePath path)
      Notifies the TreeExpansionListeners last to first, as the JDK does.
    • fireTreeCollapsed

      public void fireTreeCollapsed(TreePath path)
      Notifies the TreeExpansionListeners last to first, as the JDK does.
    • addTreeWillExpandListener

      public void addTreeWillExpandListener(TreeWillExpandListener tel)
      Fired before every expansion and collapse, programmatic or the user's, and a veto holds, as in the JDK. For a toggle in the browser the peer has already opened or closed the node by then; a veto closes or reopens it again, so the user may see it flicker.
    • removeTreeWillExpandListener

      public void removeTreeWillExpandListener(TreeWillExpandListener tel)
    • getTreeWillExpandListeners

      public TreeWillExpandListener[] getTreeWillExpandListeners()
    • fireTreeWillExpand

      public void fireTreeWillExpand(TreePath path) throws ExpandVetoException
      Notifies the TreeWillExpandListeners last to first, as the JDK does; the first veto stops it.
      Throws:
      ExpandVetoException
    • fireTreeWillCollapse

      public void fireTreeWillCollapse(TreePath path) throws ExpandVetoException
      Notifies the TreeWillExpandListeners last to first, as the JDK does; the first veto stops it.
      Throws:
      ExpandVetoException
    • getRowCount

      public int getRowCount()
    • getPathForRow

      public TreePath getPathForRow(int row)
    • getRowForPath

      public int getRowForPath(TreePath path)
      -1 when an ancestor is collapsed, so the path has no row.
    • getRowForLocation

      public int getRowForLocation(int x, int y)
      The clicked row during a user mouse handler's dispatch (the selectOnRightClick idiom), -1 otherwise, whatever the coordinates: there is no server-side pixel→row map (R_layouts_close_enough). The call graph is the JDK's, so an override of any method it reaches runs.
    • getPathForLocation

      public TreePath getPathForLocation(int x, int y)
      The clicked path during a mouse handler's dispatch, null otherwise — see getRowForLocation(int, int).
    • getClosestPathForLocation

      public TreePath getClosestPathForLocation(int x, int y)
      The clicked path during a mouse handler's dispatch, null otherwise — see getRowForLocation(int, int).
    • getClosestRowForLocation

      public int getClosestRowForLocation(int x, int y)
    • getPathBounds

      public Rectangle getPathBounds(TreePath path)
      R_layouts_close_enough — no server-side cell bounds.
    • getRowBounds

      public Rectangle getRowBounds(int row)
      R_layouts_close_enough — no server-side cell bounds.
    • getShowsRootHandles

      public boolean getShowsRootHandles()
    • setShowsRootHandles

      public void setShowsRootHandles(boolean newValue)
    • getRowHeight

      public int getRowHeight()
    • setRowHeight

      public void setRowHeight(int rowHeight)
    • isFixedRowHeight

      public boolean isFixedRowHeight()
      JDK: fixed row height means a positive rowHeight.
    • getScrollsOnExpand

      public boolean getScrollsOnExpand()
    • setScrollsOnExpand

      public void setScrollsOnExpand(boolean newValue)
    • getToggleClickCount

      public int getToggleClickCount()
    • setToggleClickCount

      public void setToggleClickCount(int clickCount)
    • getVisibleRowCount

      public int getVisibleRowCount()
    • setVisibleRowCount

      public void setVisibleRowCount(int newCount)
    • getExpandsSelectedPaths

      public boolean getExpandsSelectedPaths()
    • setExpandsSelectedPaths

      public void setExpandsSelectedPaths(boolean newValue)
    • getInvokesStopCellEditing

      public boolean getInvokesStopCellEditing()
    • setInvokesStopCellEditing

      public void setInvokesStopCellEditing(boolean newValue)
    • isLargeModel

      public boolean isLargeModel()
    • setLargeModel

      public void setLargeModel(boolean newValue)
    • getAnchorSelectionPath

      public TreePath getAnchorSelectionPath()
    • setAnchorSelectionPath

      public void setAnchorSelectionPath(TreePath newPath)
    • setLeadSelectionPath

      public void setLeadSelectionPath(TreePath newPath)
    • isEditable

      public boolean isEditable()
    • setEditable

      public void setEditable(boolean flag)
      Arms rename-in-place editing — double-click a node, or call startEditingAtPath(TreePath). false disarms it. Round-trips per R_swing_is_truth + fires the "editable" PCE.
    • isPathEditable

      public boolean isPathEditable(TreePath path)
      JDK subclass hook — defaults to isEditable().
    • getCellEditor

      public TreeCellEditor getCellEditor()
      Returns:
      the editor setCellEditor(TreeCellEditor) installed, or null — rename-in-place is driven internally and never routes through one
    • setCellEditor

      public void setCellEditor(TreeCellEditor cellEditor)
      Stores the editor and fires "cellEditor"; the editor is inert. Installing an arbitrary editor component stays out per D_gap_severity_triage sub-bucket (b), and the built-in text rename (setEditable(boolean)) is the only editing reproduced — that is the declined effect. State and notification are owed regardless (R_decline_effect_only, D_owed_events).
    • isEditing

      public boolean isEditing()
    • getEditingPath

      public TreePath getEditingPath()
    • startEditingAtPath

      public void startEditingAtPath(TreePath path)
      Selects path and opens a text editor on its node, seeded from convertValueToText(Object, boolean, boolean, boolean, int, boolean). No-op unless the tree is editable and isPathEditable(TreePath) allows the path. Any in-flight edit commits first (JDK terminate-by-commit).
    • stopEditing

      public boolean stopEditing()
      Commits the in-flight edit (write-back via valueForPathChanged); true if editing was in progress.
    • cancelEditing

      public void cancelEditing()
      Cancels the in-flight edit with no write-back.
    • getNextMatch

      public TreePath getNextMatch(String prefix, int startingRow, Position.Bias bias)
      WARN — type-ahead node search isn't modelled.
    • getDragEnabled

      public boolean getDragEnabled()
    • setDragEnabled

      public void setDragEnabled(boolean b)
    • getDropMode

      public final DropMode getDropMode()
    • setDropMode

      public final void setDropMode(DropMode dropMode)
    • getPreferredScrollableViewportSize

      public Dimension getPreferredScrollableViewportSize()
      Specified by:
      getPreferredScrollableViewportSize in interface Scrollable
    • getScrollableUnitIncrement

      public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
      Specified by:
      getScrollableUnitIncrement in interface Scrollable
    • getScrollableBlockIncrement

      public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
      Specified by:
      getScrollableBlockIncrement in interface Scrollable
    • getScrollableTracksViewportWidth

      public boolean getScrollableTracksViewportWidth()
      Specified by:
      getScrollableTracksViewportWidth in interface Scrollable
    • getScrollableTracksViewportHeight

      public boolean getScrollableTracksViewportHeight()
      Specified by:
      getScrollableTracksViewportHeight in interface Scrollable
    • getUIClassID

      public String getUIClassID()
      Overrides:
      getUIClassID in class JComponent
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JComponent
    • getUI

      public TreeUI getUI()
      Overrides:
      getUI in class JComponent
    • setUI

      public void setUI(TreeUI ui)
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()
      Specified by:
      getAccessibleContext in interface Accessible
      Overrides:
      getAccessibleContext in class Component