JIDE 3.5.15

com.jidesoft.combobox
Class TreeComboBox

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.jidesoft.combobox.AbstractComboBox
                  extended by com.jidesoft.combobox.TreeComboBox
All Implemented Interfaces:
ConverterContextSupport, AlignmentSupport, ActionListener, FocusListener, MouseListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, PopupMenuListener

public class TreeComboBox
extends AbstractComboBox

TreeComboBox is just like a normal JComboBox which you can choose a value from a drop-down tree.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jidesoft.combobox.AbstractComboBox
AbstractComboBox.AccessibleJComboBox, AbstractComboBox.ComboBoxSpinner, AbstractComboBox.ComboBoxTextField, AbstractComboBox.DefaultRendererComponent, AbstractComboBox.DefaultTextFieldEditorComponent, AbstractComboBox.EditorComponent, AbstractComboBox.EnterLazyDelegateAction, AbstractComboBox.LazyDelegateAction, AbstractComboBox.SpinnerEditorComponent
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  Object _object
           
protected  TreeModel _treeModel
           
protected  int maximumRowCount
          This protected field is implementation specific.
protected  TreeCellRenderer renderer
          This protected field is implementation specific.
static String TREE_MODEL_PROPERTY
           
 
Fields inherited from class com.jidesoft.combobox.AbstractComboBox
_dialog, _editable, _editor, _listDataListener, _oldSelectedItemReminder, _popupButton, _popupPanel, _renderer, actionCommand, CLIENT_PROPERTY_HIDE_POPUP_ON_LIST_DATA_CHANGED, CLIENT_PROPERTY_TABLE_CELL_EDITOR, CLIENT_PROPERTY_TABLE_CELL_RENDERER, COMMIT, COMMIT_OR_RESET, COMMIT_OR_REVERT, dataModel, DIALOG, DROPDOWN, HIDE_POPUP_KEY, PERSIST, PROPERTY_SELECTED_ITEM, RESET, REVERT, selectedItemReminder
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TreeComboBox()
           
TreeComboBox(Hashtable<?,?> objects)
          Creates a new TreeComboBox.
TreeComboBox(Object[] objects)
          Creates a new TreeComboBox.
TreeComboBox(TreeModel model)
          Creates a new TreeComboBox.
TreeComboBox(TreeNode root)
          Creates a new TreeComboBox.
TreeComboBox(TreeNode root, boolean asksAllowsChildren)
          Creates a new TreeComboBox.
TreeComboBox(Vector<?> objects)
          Creates a new TreeComboBox.
 
Method Summary
protected  String convertElementToString(Object object)
          Converts the element from object to string so that i can display in the text field of TreeComboBox.
 AbstractComboBox.EditorComponent createEditorComponent()
          Subclass should implement this method to create the actual editor component.
 PopupPanel createPopupComponent()
          Subclass should implement this method to create the actual popup component.
protected  JTree createTree(TreeModel model)
          Creates the tree.
protected  TreeChooserPanel createTreeChooserPanel(TreeModel model)
          Creates the TreeChooserPanel.
 TreeCellRenderer getCellRenderer()
          Returns the renderer used to display the selected item in the JComboBox field.
protected  JComponent getDelegateTarget()
           
 int getMaximumRowCount()
          Returns the maximum number of items the combo box can display without a scrollbar.
 JTree getTree()
          Gets the underlying JTree.
 TreeModel getTreeModel()
          Gets the tree model that will be used by the tree in the popup.
protected  void initComponent(ComboBoxModel model)
          Initialize this component such as creating button, editor etc.
 boolean isDoubleClickExpand()
          Get the flag indicating if the mouse double click would expand the tree path instead of just select it.
protected  boolean isValidSelection(TreePath path)
          Checks if a given tree path is a valid selection for combobox.
protected  List<TreePath> populateTreePaths(JTree tree)
           
 void setCellRenderer(TreeCellRenderer aRenderer)
          Sets the renderer that paints the list items and the item selected from the list in the JComboBox field.
 void setDoubleClickExpand(boolean doubleClickExpand)
          Set the flag indicating if the mouse double click would expand the tree path instead of just select it.
 void setMaximumRowCount(int count)
          Sets the maximum number of rows the JComboBox displays.
 void setTreeModel(TreeModel treeModel)
          Sets the tree model that will be used by the tree in the popup.
protected  void setupTree(JTree tree)
          Setups the JTree for the tree used in the popup panel.
 
Methods inherited from class com.jidesoft.combobox.AbstractComboBox
actionPerformed, addActionListener, addItemListener, addNotify, addPopupMenuListener, calculatePopupLocation, comboBoxSelected, commitEdit, commitEditWithFocusLostBehavior, configurePropertiesFromAction, createActionPropertyChangeListener, createButtonComponent, createDefaultButton, createPopupWindow, createPropertyChangeListener, createSpinner, createTextField, customizeButton, customizeDialog, customizeDialogLocation, customizePopup, delegateKeyStrokes, equals, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, focusGained, focusLost, getAccessibleContext, getAction, getActionCommand, getActionListeners, getBackground, getBaseline, getConverter, getConverterContext, getDefaultCancelAction, getDefaultOKAction, getDelegateKeyStrokes, getDialogCancelAction, getDialogOKAction, getDisabledBackground, getDisabledForeground, getEditor, getFocusLostBehavior, getForeground, getHorizontalAlignment, getItemListeners, getModel, getPopupButton, getPopupCancelBehavior, getPopupLocation, getPopupMenuListeners, getPopupPanel, getPopupType, getPrototypeDisplayValue, getRenderer, getSelectedItem, getSelectedItemForPopupPanel, getSelectedObjects, getType, getVerticalAlignment, hidePopup, initComponent, installColorFontAndBorder, installListener, isButtonOnly, isButtonVisible, isClearSelectionOnListDataChanged, isEditable, isHidePopupOnListDataChanged, isKeepPopupSize, isOpaque, isPopupVisible, isPopupVolatile, isStretchToFit, isToggleValueOnDoubleClick, isUpdateFromPopupOnFly, listDataChanged, modelUpdated, mouseClicked, mouseEntered, mouseExited, mousePressed, mouseReleased, notifyUser, paintComponent, popupMenuCanceled, popupMenuWillBecomeInvisible, popupMenuWillBecomeVisible, processKeyBinding, removeActionListener, removeItemListener, removeNotify, removePopupMenuListener, resetEdit, resetPopup, revertEdit, selectedItemChanged, setAction, setActionCommand, setBackground, setBorder, setButtonOnly, setButtonVisible, setClearSelectionOnListDataChanged, setConverter, setConverterContext, setDisabledBackground, setDisabledForeground, setEditable, setEditor, setEnabled, setFocusLostBehavior, setForeground, setHidePopupOnListDataChanged, setHorizontalAlignment, setKeepPopupSize, setModel, setPopupButton, setPopupCancelBehavior, setPopupType, setPopupVisible, setPopupVolatile, setPrototypeDisplayValue, setRenderer, setSelectedItem, setSelectedItem, setStretchToFit, setToggleValueOnDoubleClick, setType, setVerticalAlignment, showPopup, showPopupPanel, showPopupPanelAsPopup, undelegateKeyStrokes, uninstallListener, updateToolTipTextForChildren, updateUI, validateValueForNonEditable
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

renderer

protected TreeCellRenderer renderer
This protected field is implementation specific. Do not access directly or override. Use the accessor methods instead.

See Also:
getCellRenderer(), setCellRenderer(javax.swing.tree.TreeCellRenderer)

maximumRowCount

protected int maximumRowCount
This protected field is implementation specific. Do not access directly or override. Use the accessor methods instead.

See Also:
getMaximumRowCount(), setMaximumRowCount(int)

_object

protected Object _object

_treeModel

protected TreeModel _treeModel

TREE_MODEL_PROPERTY

public static final String TREE_MODEL_PROPERTY
See Also:
Constant Field Values
Constructor Detail

TreeComboBox

public TreeComboBox()

TreeComboBox

public TreeComboBox(Object[] objects)
Creates a new TreeComboBox.

Parameters:
objects - the objects

TreeComboBox

public TreeComboBox(Vector<?> objects)
Creates a new TreeComboBox.

Parameters:
objects - the objects

TreeComboBox

public TreeComboBox(Hashtable<?,?> objects)
Creates a new TreeComboBox.

Parameters:
objects - the objects

TreeComboBox

public TreeComboBox(TreeNode root)
Creates a new TreeComboBox.

Parameters:
root - the root node

TreeComboBox

public TreeComboBox(TreeNode root,
                    boolean asksAllowsChildren)
Creates a new TreeComboBox.

Parameters:
root - the root node
asksAllowsChildren - the flag indicating if allows children

TreeComboBox

public TreeComboBox(TreeModel model)
Creates a new TreeComboBox.

Parameters:
model - the tree model
Method Detail

initComponent

protected void initComponent(ComboBoxModel model)
Description copied from class: AbstractComboBox
Initialize this component such as creating button, editor etc. All subclasses must call this method in the constructor to initialize the ComboBox.

Overrides:
initComponent in class AbstractComboBox
Parameters:
model - ComboBoxModel if any. If it's null, use InfiniteComboBoxModel.

populateTreePaths

protected List<TreePath> populateTreePaths(JTree tree)

createEditorComponent

public AbstractComboBox.EditorComponent createEditorComponent()
Description copied from class: AbstractComboBox
Subclass should implement this method to create the actual editor component.

Specified by:
createEditorComponent in class AbstractComboBox
Returns:
the editor component

createPopupComponent

public PopupPanel createPopupComponent()
Description copied from class: AbstractComboBox
Subclass should implement this method to create the actual popup component.

Specified by:
createPopupComponent in class AbstractComboBox
Returns:
the popup component

createTreeChooserPanel

protected TreeChooserPanel createTreeChooserPanel(TreeModel model)
Creates the TreeChooserPanel. Subclass can override this method to create its own TreeChooserPanel. Below is the default implement of this method.

 TreeChooserPanel panel = new TreeChooserPanel(object) {
      protected void setupTree(final JTree tree) {
          super.setupTree(tree);
          tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
              public void valueChanged(TreeSelectionEvent e) {
                  if (e.getPath() != null && !Boolean.TRUE.equals(tree.getClientProperty(PopupPanel.SELECTED_BY_MOUSE_ROLLOVER)))
 {
                      if (isValidSelection(e.getPath())) {
                          setSelectedObject(item, false);
                          getEditor().setItem(e.getPath());
                          getEditor().selectAll();
                      }
                  }
              }
          });
          TreeComboBox.this.setupTree(tree);
      }
 

protected boolean isValidSelection(TreePath path) { return TreeComboBox.this.isValidSelection(path); } };

Parameters:
model - the tree model
Returns:
TreeChooserPanel.

createTree

protected JTree createTree(TreeModel model)
Creates the tree. By default, we will return null, meaning the default JTree created by TreeChooserPanel will be used. Subclass can override this method to create other types of tree.

Parameters:
model - the tree model.
Returns:
the tree.

setupTree

protected void setupTree(JTree tree)
Setups the JTree for the tree used in the popup panel. You can override this method to customize the JTree.

Parameters:
tree - the JTree instance

setMaximumRowCount

public void setMaximumRowCount(int count)
Sets the maximum number of rows the JComboBox displays. If the number of objects in the model is greater than count, the combo box uses a scrollbar.

Parameters:
count - an integer specifying the maximum number of items to display in the list before using a scrollbar description: The maximum number of rows the popup should have

getMaximumRowCount

public int getMaximumRowCount()
Returns the maximum number of items the combo box can display without a scrollbar.

Returns:
an integer specifying the maximum number of items that are displayed in the list before using a scrollbar

setCellRenderer

public void setCellRenderer(TreeCellRenderer aRenderer)
Sets the renderer that paints the list items and the item selected from the list in the JComboBox field. The renderer is used if the JComboBox is not editable. If it is editable, the editor is used to render and edit the selected item.

The default renderer displays a string or an icon. Other renderers can handle graphic images and composite items.

To display the selected item, aRenderer.getListCellRendererComponent is called, passing the list object and an index of -1.

Parameters:
aRenderer - the ListCellRenderer that displays the selected item expert: true description: The renderer that paints the item selected in the list.
See Also:
AbstractComboBox.setEditor(javax.swing.ComboBoxEditor)

getCellRenderer

public TreeCellRenderer getCellRenderer()
Returns the renderer used to display the selected item in the JComboBox field.

Returns:
the ListCellRenderer that displays the selected item.

getTree

public JTree getTree()
Gets the underlying JTree. It will return a not null value only when the tree has ever been displayed. If you want to customize the tree, it's better to override createTreeChooserPanel(javax.swing.tree.TreeModel) method and create your own TreeChooserPanel and JTree.

If you want to programmatically set selected row on the JTree, you can use this method. However do not keep the returned value and use it later because combobox may create a new JTree if the popup is volatile.

Please note, this method will show the popup automatically if the combobox itself is showing (isShowing returns true). Otherwise, it could return null if the popup was never shown before.

Returns:
tree

getDelegateTarget

protected JComponent getDelegateTarget()
Overrides:
getDelegateTarget in class AbstractComboBox

convertElementToString

protected String convertElementToString(Object object)
Converts the element from object to string so that i can display in the text field of TreeComboBox. Subclass can override this method to provide one's own conversion.

Parameters:
object - the object
Returns:
the string representing the object.

isValidSelection

protected boolean isValidSelection(TreePath path)
Checks if a given tree path is a valid selection for combobox. By default it always return true, meaning all tree path could be used as a valid value of combo box.Subclass can override this method to limit the valid selection to certain tree path. For example, check if last node in the tree path is leaf node and only allow leaf node to be a valid selection.

Parameters:
path - the tree path
Returns:
true or false.

getTreeModel

public TreeModel getTreeModel()
Gets the tree model that will be used by the tree in the popup.

Returns:
the tree model.

setTreeModel

public void setTreeModel(TreeModel treeModel)
Sets the tree model that will be used by the tree in the popup.

Parameters:
treeModel - the tree model

isDoubleClickExpand

public boolean isDoubleClickExpand()
Get the flag indicating if the mouse double click would expand the tree path instead of just select it.

By default, the flag is false to keep the original behavior. You could set it to true if you want choose leaf node only.

Returns:
true if the mouse double click would expand the tree path. Otherwise false.

setDoubleClickExpand

public void setDoubleClickExpand(boolean doubleClickExpand)
Set the flag indicating if the mouse double click would expand the tree path instead of just select it.

Parameters:
doubleClickExpand - the flag
See Also:
isDoubleClickExpand()

JIDE 3.5.15