📄 jtree.java
字号:
listenerList.add(TreeSelectionListener.class, listener); } /** * Removes a <code>TreeSelectionListener</code> object from the tree. * * @param listener the listener to remove */ public void removeTreeSelectionListener(TreeSelectionListener listener) { listenerList.remove(TreeSelectionListener.class, listener); } /** * Returns all added <code>TreeSelectionListener</code> objects. * * @return an array of listeners */ public TreeSelectionListener[] getTreeSelectionListeners() { return (TreeSelectionListener[]) getListeners(TreeSelectionListener.class); } /** * Notifies all listeners when the selection of the tree changed. * * @param event the event to send */ protected void fireValueChanged(TreeSelectionEvent event) { TreeSelectionListener[] listeners = getTreeSelectionListeners(); for (int index = 0; index < listeners.length; ++index) listeners[index].valueChanged(event); } /** * Adds a <code>TreeWillExpandListener</code> object to the tree. * * @param listener the listener to add */ public void addTreeWillExpandListener(TreeWillExpandListener listener) { listenerList.add(TreeWillExpandListener.class, listener); } /** * Removes a <code>TreeWillExpandListener</code> object from the tree. * * @param listener the listener to remove */ public void removeTreeWillExpandListener(TreeWillExpandListener listener) { listenerList.remove(TreeWillExpandListener.class, listener); } /** * Returns all added <code>TreeWillExpandListener</code> objects. * * @return an array of listeners */ public TreeWillExpandListener[] getTreeWillExpandListeners() { return (TreeWillExpandListener[]) getListeners(TreeWillExpandListener.class); } /** * Notifies all listeners that the tree will collapse. * * @param path the path to the node that will collapse */ public void fireTreeWillCollapse(TreePath path) throws ExpandVetoException { TreeExpansionEvent event = new TreeExpansionEvent(this, path); TreeWillExpandListener[] listeners = getTreeWillExpandListeners(); for (int index = 0; index < listeners.length; ++index) listeners[index].treeWillCollapse(event); } /** * Notifies all listeners that the tree will expand. * * @param path the path to the node that will expand */ public void fireTreeWillExpand(TreePath path) throws ExpandVetoException { TreeExpansionEvent event = new TreeExpansionEvent(this, path); TreeWillExpandListener[] listeners = getTreeWillExpandListeners(); for (int index = 0; index < listeners.length; ++index) listeners[index].treeWillExpand(event); } /** * Returns the model of this <code>JTree</code> object. * * @return the associated <code>TreeModel</code> */ public TreeModel getModel() { return treeModel; } /** * Sets the model to use in <code>JTree</code>. * * @param model the <code>TreeModel</code> to use */ public void setModel(TreeModel model) { if (treeModel == model) return; TreeModel oldValue = treeModel; treeModel = model; firePropertyChange(TREE_MODEL_PROPERTY, oldValue, model); } /** * Checks if this <code>JTree</code> object is editable. * * @return <code>true</code> if this tree object is editable, * <code>false</code> otherwise */ public boolean isEditable() { return editable; } /** * Sets the <code>editable</code> property. * * @param flag <code>true</code> to make this tree object editable, * <code>false</code> otherwise */ public void setEditable(boolean flag) { if (editable == flag) return; boolean oldValue = editable; editable = flag; firePropertyChange(EDITABLE_PROPERTY, oldValue, editable); } /** * Checks if the root element is visible. * * @return <code>true</code> if the root element is visible, * <code>false</code> otherwise */ public boolean isRootVisible() { return rootVisible; } public void setRootVisible(boolean flag) { if (rootVisible == flag) return; boolean oldValue = rootVisible; rootVisible = flag; firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, flag); } public boolean getShowsRootHandles() { return showsRootHandles; } public void setShowsRootHandles(boolean flag) { if (showsRootHandles == flag) return; boolean oldValue = showsRootHandles; showsRootHandles = flag; firePropertyChange(SHOWS_ROOT_HANDLES_PROPERTY, oldValue, flag); } public TreeCellEditor getCellEditor() { return cellEditor; } public void setCellEditor(TreeCellEditor editor) { if (cellEditor == editor) return; TreeCellEditor oldValue = cellEditor; cellEditor = editor; firePropertyChange(CELL_EDITOR_PROPERTY, oldValue, editor); } public TreeCellRenderer getCellRenderer() { return cellRenderer; } public void setCellRenderer(TreeCellRenderer newRenderer) { if (cellRenderer == newRenderer) return; TreeCellRenderer oldValue = cellRenderer; cellRenderer = newRenderer; firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, newRenderer); } public TreeSelectionModel getSelectionModel() { return selectionModel; } public void setSelectionModel(TreeSelectionModel model) { if (selectionModel == model) return; TreeSelectionModel oldValue = selectionModel; selectionModel = model; firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, model); } public int getVisibleRowCount() { return visibleRowCount; } public void setVisibleRowCount(int rows) { if (visibleRowCount == rows) return; int oldValue = visibleRowCount; visibleRowCount = rows; firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldValue, rows); } public boolean isLargeModel() { return largeModel; } public void setLargeModel(boolean large) { if (largeModel == large) return; boolean oldValue = largeModel; largeModel = large; firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, large); } public int getRowHeight() { return rowHeight; } public void setRowHeight(int height) { if (rowHeight == height) return; int oldValue = rowHeight; rowHeight = height; firePropertyChange(ROW_HEIGHT_PROPERTY, oldValue, height); } public boolean isFixedRowHeight() { return rowHeight > 0; } public boolean getInvokesStopCellEditing() { return invokesStopCellEditing; } public void setInvokesStopCellEditing(boolean invoke) { if (invokesStopCellEditing == invoke) return; boolean oldValue = invokesStopCellEditing; invokesStopCellEditing = invoke; firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY, oldValue, invoke); } /** * @since 1.3 */ public int getToggleClickCount() { return toggleClickCount; } /** * @since 1.3 */ public void setToggleClickCount(int count) { if (toggleClickCount == count) return; int oldValue = toggleClickCount; toggleClickCount = count; firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldValue, count); } public void scrollPathToVisible(TreePath path) { if (path == null) return; Rectangle rect = getPathBounds(path); if (rect == null) return; scrollRectToVisible(rect); } public void scrollRowToVisible(int row) { scrollPathToVisible(getPathForRow(row)); } public boolean getScrollsOnExpand() { return scrollsOnExpand; } public void setScrollsOnExpand(boolean scroll) { if (scrollsOnExpand == scroll) return; boolean oldValue = scrollsOnExpand; scrollsOnExpand = scroll; firePropertyChange(SCROLLS_ON_EXPAND_PROPERTY, oldValue, scroll); } public void setSelectionPath(TreePath path) { selectionModel.setSelectionPath(path); } public void setSelectionPaths(TreePath[] paths) { selectionModel.setSelectionPaths(paths); } public void setSelectionRow(int row) { TreePath path = getPathForRow(row); if (path != null) selectionModel.setSelectionPath(path); } public void setSelectionRows(int[] rows) { // Make sure we have an UI so getPathForRow() does not return null. if (rows == null || getUI() == null) return; TreePath[] paths = new TreePath[rows.length]; for (int i = rows.length - 1; i >= 0; --i) paths[i] = getPathForRow(rows[i]); setSelectionPaths(paths); } public void setSelectionInterval(int index0, int index1) { TreePath[] paths = getPathBetweenRows(index0, index1); if (paths != null) setSelectionPaths(paths); } public void addSelectionPath(TreePath path) { selectionModel.addSelectionPath(path); } public void addSelectionPaths(TreePath[] paths) { selectionModel.addSelectionPaths(paths); } public void addSelectionRow(int row) { TreePath path = getPathForRow(row); if (path != null) selectionModel.addSelectionPath(path); } public void addSelectionRows(int[] rows) { // Make sure we have an UI so getPathForRow() does not return null. if (rows == null || getUI() == null) return; TreePath[] paths = new TreePath[rows.length]; for (int i = rows.length - 1; i >= 0; --i) paths[i] = getPathForRow(rows[i]); addSelectionPaths(paths); } public void addSelectionInterval(int index0, int index1) { TreePath[] paths = getPathBetweenRows(index0, index1); if (paths != null) addSelectionPaths(paths); } public void removeSelectionPath(TreePath path) { selectionModel.removeSelectionPath(path); } public void removeSelectionPaths(TreePath[] paths) { selectionModel.removeSelectionPaths(paths); } public void removeSelectionRow(int row) { TreePath path = getPathForRow(row); if (path != null) selectionModel.removeSelectionPath(path); } public void removeSelectionRows(int[] rows) { // Make sure we have an UI so getPathForRow() does not return null. if (rows == null || getUI() == null) return; TreePath[] paths = new TreePath[rows.length]; for (int i = rows.length - 1; i >= 0; --i) paths[i] = getPathForRow(rows[i]); removeSelectionPaths(paths); } public void removeSelectionInterval(int index0, int index1) { TreePath[] paths = getPathBetweenRows(index0, index1); if (paths != null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -