src/java.desktop/share/classes/javax/swing/JTree.java
Print this page
@@ -20,28 +20,31 @@
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
-
package javax.swing;
import java.awt.*;
import java.awt.event.*;
-import java.beans.*;
+import java.beans.JavaBean;
+import java.beans.BeanProperty;
+import java.beans.ConstructorProperties;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.*;
import java.util.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.tree.*;
import javax.swing.text.Position;
import javax.accessibility.*;
+
import sun.swing.SwingUtilities2;
import sun.swing.SwingUtilities2.Section;
import static sun.swing.SwingUtilities2.Section.*;
-
/**
* <a name="jtree_description"></a>
* A control that displays a set of hierarchical data as an outline.
* You can find task-oriented documentation and examples of using trees in
* <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html">How to Use Trees</a>,
@@ -132,19 +135,18 @@
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans™
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*</p>
- * @beaninfo
- * attribute: isContainer false
- * description: A component that displays a set of hierarchical data as an outline.
*
* @author Rob Davis
* @author Ray Ryan
* @author Scott Violet
* @since 1.2
*/
+@JavaBean(defaultProperty = "UI", description = "A component that displays a set of hierarchical data as an outline.")
+@SwingContainer(false)
@SuppressWarnings("serial")
public class JTree extends JComponent implements Scrollable, Accessible
{
/**
* @see #getUIClassID
@@ -685,16 +687,13 @@
* <p>
* This is a bound property.
*
* @param ui the <code>TreeUI</code> L&F object
* @see UIDefaults#getUI
- * @beaninfo
- * bound: true
- * hidden: true
- * attribute: visualUpdate true
- * description: The UI object that implements the Component's LookAndFeel.
*/
+ @BeanProperty(hidden = true, visualUpdate = true, description
+ = "The UI object that implements the Component's LookAndFeel.")
public void setUI(TreeUI ui) {
if (this.ui != ui) {
settingUI = true;
uiTreeExpansionListener = null;
try {
@@ -726,10 +725,11 @@
*
* @return the string "TreeUI"
* @see JComponent#getUIClassID
* @see UIDefaults#getUI
*/
+ @BeanProperty(bound = false)
public String getUIClassID() {
return uiClassID;
}
@@ -748,15 +748,13 @@
* draw each cell.
* <p>
* This is a bound property.
*
* @param x the <code>TreeCellRenderer</code> that is to render each cell
- * @beaninfo
- * bound: true
- * description: The TreeCellRenderer that will be used to draw
- * each cell.
*/
+ @BeanProperty(description
+ = "The TreeCellRenderer that will be used to draw each cell.")
public void setCellRenderer(TreeCellRenderer x) {
TreeCellRenderer oldValue = cellRenderer;
cellRenderer = x;
firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, cellRenderer);
@@ -769,14 +767,13 @@
* setting.
* <p>
* This is a bound property.
*
* @param flag a boolean value, true if the tree is editable
- * @beaninfo
- * bound: true
- * description: Whether the tree is editable.
*/
+ @BeanProperty(description
+ = "Whether the tree is editable.")
public void setEditable(boolean flag) {
boolean oldValue = this.editable;
this.editable = flag;
firePropertyChange(EDITABLE_PROPERTY, oldValue, flag);
@@ -804,15 +801,13 @@
* method is invoked on all listeners.
* <p>
* This is a bound property.
*
* @param cellEditor the <code>TreeCellEditor</code> to use
- * @beaninfo
- * bound: true
- * description: The cell editor. A null value implies the tree
- * cannot be edited.
*/
+ @BeanProperty(description
+ = "The cell editor. A null value implies the tree cannot be edited.")
public void setCellEditor(TreeCellEditor cellEditor) {
TreeCellEditor oldEditor = this.cellEditor;
this.cellEditor = cellEditor;
firePropertyChange(CELL_EDITOR_PROPERTY, oldEditor, cellEditor);
@@ -842,14 +837,13 @@
* Sets the <code>TreeModel</code> that will provide the data.
* <p>
* This is a bound property.
*
* @param newModel the <code>TreeModel</code> that is to provide the data
- * @beaninfo
- * bound: true
- * description: The TreeModel that will provide the data.
*/
+ @BeanProperty(description
+ = "The TreeModel that will provide the data.")
public void setModel(TreeModel newModel) {
clearSelection();
TreeModel oldModel = treeModel;
@@ -901,15 +895,13 @@
* <p>
* This is a bound property.
*
* @param rootVisible true if the root node of the tree is to be displayed
* @see #rootVisible
- * @beaninfo
- * bound: true
- * description: Whether or not the root node
- * from the TreeModel is visible.
*/
+ @BeanProperty(description
+ = "Whether or not the root node from the TreeModel is visible.")
public void setRootVisible(boolean rootVisible) {
boolean oldValue = this.rootVisible;
this.rootVisible = rootVisible;
firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, this.rootVisible);
@@ -930,15 +922,13 @@
*
* @param newValue <code>true</code> if root handles should be displayed;
* otherwise, <code>false</code>
* @see #showsRootHandles
* @see #getShowsRootHandles
- * @beaninfo
- * bound: true
- * description: Whether the node handles are to be
- * displayed.
*/
+ @BeanProperty(description
+ = "Whether the node handles are to be displayed.")
public void setShowsRootHandles(boolean newValue) {
boolean oldValue = showsRootHandles;
TreeModel model = getModel();
showsRootHandles = newValue;
@@ -968,14 +958,13 @@
* queried for each row's height.
* <p>
* This is a bound property.
*
* @param rowHeight the height of each cell, in pixels
- * @beaninfo
- * bound: true
- * description: The height of each cell.
*/
+ @BeanProperty(description
+ = "The height of each cell.")
public void setRowHeight(int rowHeight)
{
int oldValue = this.rowHeight;
this.rowHeight = rowHeight;
@@ -999,10 +988,11 @@
/**
* Returns true if the height of each display row is a fixed size.
*
* @return true if the height of each row is a fixed size
*/
+ @BeanProperty(bound = false)
public boolean isFixedRowHeight()
{
return (rowHeight > 0);
}
@@ -1013,15 +1003,13 @@
* <p>
* This is a bound property.
*
* @param newValue true to suggest a large model to the UI
* @see #largeModel
- * @beaninfo
- * bound: true
- * description: Whether the UI should use a
- * large model.
*/
+ @BeanProperty(description
+ = "Whether the UI should use a large model.")
public void setLargeModel(boolean newValue) {
boolean oldValue = largeModel;
largeModel = newValue;
firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, newValue);
@@ -1046,16 +1034,14 @@
* Fires a property change for the INVOKES_STOP_CELL_EDITING_PROPERTY.
*
* @param newValue true means that <code>stopCellEditing</code> is invoked
* when editing is interrupted, and data is saved; false means that
* <code>cancelCellEditing</code> is invoked, and changes are lost
- * @beaninfo
- * bound: true
- * description: Determines what happens when editing is interrupted,
- * selecting another node in the tree, a change in the
- * tree's data, or some other means.
*/
+ @BeanProperty(description
+ = "Determines what happens when editing is interrupted, selecting another node in the tree, "
+ + "a change in the tree's data, or some other means.")
public void setInvokesStopCellEditing(boolean newValue) {
boolean oldValue = invokesStopCellEditing;
invokesStopCellEditing = newValue;
firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY, oldValue,
@@ -1088,15 +1074,13 @@
* This is a bound property.
*
* @param newValue <code>false</code> to disable scrolling on expansion;
* <code>true</code> to enable it
* @see #getScrollsOnExpand
- *
- * @beaninfo
- * bound: true
- * description: Indicates if a node descendant should be scrolled when expanded.
*/
+ @BeanProperty(description
+ = "Indicates if a node descendant should be scrolled when expanded.")
public void setScrollsOnExpand(boolean newValue) {
boolean oldValue = scrollsOnExpand;
scrollsOnExpand = newValue;
scrollsOnExpandSet = true;
@@ -1119,14 +1103,13 @@
* <p>
* This is a bound property.
*
* @param clickCount the number of mouse clicks to get a node expanded or closed
* @since 1.3
- * @beaninfo
- * bound: true
- * description: Number of clicks before a node will expand/collapse.
*/
+ @BeanProperty(description
+ = "Number of clicks before a node will expand/collapse.")
public void setToggleClickCount(int clickCount) {
int oldCount = toggleClickCount;
toggleClickCount = clickCount;
firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldCount,
@@ -1158,15 +1141,13 @@
* This is a bound property.
*
* @param newValue the new value for <code>expandsSelectedPaths</code>
*
* @since 1.3
- * @beaninfo
- * bound: true
- * description: Indicates whether changes to the selection should make
- * the parent of the path visible.
*/
+ @BeanProperty(description
+ = "Indicates whether changes to the selection should make the parent of the path visible.")
public void setExpandsSelectedPaths(boolean newValue) {
boolean oldValue = expandsSelectedPaths;
expandsSelectedPaths = newValue;
firePropertyChange(EXPANDS_SELECTED_PATHS_PROPERTY, oldValue,
@@ -1210,15 +1191,13 @@
* @see java.awt.GraphicsEnvironment#isHeadless
* @see #getDragEnabled
* @see #setTransferHandler
* @see TransferHandler
* @since 1.4
- *
- * @beaninfo
- * description: determines whether automatic drag handling is enabled
- * bound: false
*/
+ @BeanProperty(bound = false, description
+ = "determines whether automatic drag handling is enabled")
public void setDragEnabled(boolean b) {
checkDragEnabled(b);
dragEnabled = b;
}
@@ -1503,10 +1482,11 @@
* @return the drop location
* @see #setDropMode
* @see TransferHandler#canImport(TransferHandler.TransferSupport)
* @since 1.6
*/
+ @BeanProperty(bound = false)
public final DropLocation getDropLocation() {
return dropLocation;
}
private void startDropTimer() {
@@ -1633,10 +1613,11 @@
* {@code isRootVisible()} is {@code true}. This returns {@code 0} if
* the UI has not been set.
*
* @return the number of viewable nodes
*/
+ @BeanProperty(bound = false)
public int getRowCount() {
TreeUI tree = getUI();
if(tree != null)
return tree.getRowCount(this);
@@ -1675,14 +1656,13 @@
* <p>
* This is a bound property.
*
* @param newPath the new lead path
* @since 1.3
- * @beaninfo
- * bound: true
- * description: Lead selection path
*/
+ @BeanProperty(description
+ = "Lead selection path")
public void setLeadSelectionPath(TreePath newPath) {
TreePath oldValue = leadPath;
leadPath = newPath;
firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, newPath);
@@ -1703,14 +1683,13 @@
* <p>
* This is a bound property.
*
* @param newPath the new anchor path
* @since 1.3
- * @beaninfo
- * bound: true
- * description: Anchor selection path
*/
+ @BeanProperty(description
+ = "Anchor selection path")
public void setAnchorSelectionPath(TreePath newPath) {
TreePath oldValue = anchorPath;
anchorPath = newPath;
firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, newPath);
@@ -1826,10 +1805,11 @@
*
* @return the last path component of the selected path, or
* <code>null</code> if nothing is selected
* @see TreePath#getLastPathComponent
*/
+ @BeanProperty(bound = false)
public Object getLastSelectedPathComponent() {
TreePath selPath = getSelectionModel().getSelectionPath();
if(selPath != null)
return selPath.getLastPathComponent();
@@ -1892,30 +1872,33 @@
/**
* Returns the number of nodes selected.
*
* @return the number of nodes selected
*/
+ @BeanProperty(bound = false)
public int getSelectionCount() {
return selectionModel.getSelectionCount();
}
/**
* Returns the smallest selected row. If the selection is empty, or
* none of the selected paths are viewable, {@code -1} is returned.
*
* @return the smallest selected row
*/
+ @BeanProperty(bound = false)
public int getMinSelectionRow() {
return getSelectionModel().getMinSelectionRow();
}
/**
* Returns the largest selected row. If the selection is empty, or
* none of the selected paths are viewable, {@code -1} is returned.
*
* @return the largest selected row
*/
+ @BeanProperty(bound = false)
public int getMaxSelectionRow() {
return getSelectionModel().getMaxSelectionRow();
}
/**
@@ -1923,10 +1906,11 @@
*
* @return an integer giving the row index of the lead path,
* where 0 is the first row in the display; or -1
* if <code>leadPath</code> is <code>null</code>
*/
+ @BeanProperty(bound = false)
public int getLeadSelectionRow() {
TreePath leadPath = getLeadSelectionPath();
if (leadPath != null) {
return getRowForPath(leadPath);
@@ -2196,10 +2180,11 @@
* @param row an integer specifying a row
* @return the <code>TreePath</code> to the specified node,
* <code>null</code> if <code>row < 0</code>
* or <code>row >= getRowCount()</code>
*/
+ @BeanProperty(bound = false)
public TreePath getPathForRow(int row) {
TreeUI tree = getUI();
if(tree != null)
return tree.getPathForRow(this, row);
@@ -2366,10 +2351,11 @@
* edited can be obtained using <code>getSelectionPath</code>.
*
* @return true if the user is currently editing a node
* @see #getSelectionPath
*/
+ @BeanProperty(bound = false)
public boolean isEditing() {
TreeUI tree = getUI();
if(tree != null)
return tree.isEditing(this);
@@ -2428,10 +2414,11 @@
/**
* Returns the path to the element that is currently being edited.
*
* @return the <code>TreePath</code> for the node being edited
*/
+ @BeanProperty(bound = false)
public TreePath getEditingPath() {
TreeUI tree = getUI();
if(tree != null)
return tree.getEditingPath(this);
@@ -2455,14 +2442,13 @@
* This is a bound property.
*
* @param selectionModel the <code>TreeSelectionModel</code> to use,
* or <code>null</code> to disable selections
* @see TreeSelectionModel
- * @beaninfo
- * bound: true
- * description: The tree's selection model.
*/
+ @BeanProperty(description
+ = "The tree's selection model.")
public void setSelectionModel(TreeSelectionModel selectionModel) {
if(selectionModel == null)
selectionModel = EmptySelectionModel.sharedInstance();
TreeSelectionModel oldValue = this.selectionModel;
@@ -2698,10 +2684,11 @@
/**
* Returns true if the selection is currently empty.
*
* @return true if the selection is currently empty
*/
+ @BeanProperty(bound = false)
public boolean isSelectionEmpty() {
return getSelectionModel().isSelectionEmpty();
}
/**
@@ -2736,10 +2723,11 @@
*
* @return all of the <code>TreeExpansionListener</code>s added or an empty
* array if no listeners have been added
* @since 1.4
*/
+ @BeanProperty(bound = false)
public TreeExpansionListener[] getTreeExpansionListeners() {
return listenerList.getListeners(TreeExpansionListener.class);
}
/**
@@ -2768,10 +2756,11 @@
*
* @return all of the <code>TreeWillExpandListener</code>s added or an empty
* array if no listeners have been added
* @since 1.4
*/
+ @BeanProperty(bound = false)
public TreeWillExpandListener[] getTreeWillExpandListeners() {
return listenerList.getListeners(TreeWillExpandListener.class);
}
/**
@@ -2927,10 +2916,11 @@
*
* @return all of the <code>TreeSelectionListener</code>s added or an empty
* array if no listeners have been added
* @since 1.4
*/
+ @BeanProperty(bound = false)
public TreeSelectionListener[] getTreeSelectionListeners() {
return listenerList.getListeners(TreeSelectionListener.class);
}
/**
@@ -2978,14 +2968,13 @@
* and will adjust the preferred size and size of that scrollpane.
* <p>
* This is a bound property.
*
* @param newCount the number of rows to display
- * @beaninfo
- * bound: true
- * description: The number of rows that are to be displayed.
*/
+ @BeanProperty(description
+ = "The number of rows that are to be displayed.")
public void setVisibleRowCount(int newCount) {
int oldCount = visibleRowCount;
visibleRowCount = newCount;
firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldCount,
@@ -3457,10 +3446,11 @@
* determined from <code>getVisibleRowCount</code> and the width
* is the current preferred width.
*
* @return a <code>Dimension</code> object containing the preferred size
*/
+ @BeanProperty(bound = false)
public Dimension getPreferredScrollableViewportSize() {
int width = getPreferredSize().width;
int visRows = getVisibleRowCount();
int height = -1;
@@ -3563,10 +3553,11 @@
* ensure that the tree is never smaller than its viewport.
*
* @return whether the tree should track the width of the viewport
* @see Scrollable#getScrollableTracksViewportWidth
*/
+ @BeanProperty(bound = false)
public boolean getScrollableTracksViewportWidth() {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
return parent.getWidth() > getPreferredSize().width;
}
@@ -3580,10 +3571,11 @@
* ensure that the tree is never smaller than its viewport.
*
* @return whether the tree should track the height of the viewport
* @see Scrollable#getScrollableTracksViewportHeight
*/
+ @BeanProperty(bound = false)
public boolean getScrollableTracksViewportHeight() {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
return parent.getHeight() > getPreferredSize().height;
}
@@ -4158,10 +4150,11 @@
* A new AccessibleJTree instance is created if necessary.
*
* @return an AccessibleJTree that serves as the
* AccessibleContext of this JTree
*/
+ @BeanProperty(bound = false)
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJTree();
}
return accessibleContext;