Adding multiple row editor to TreeCellEditor
Hey all,
I need to have a text field, check box and a combo box all as part of an inline editor for a tree node. When the user hits NEW to insert a new tree node, or edit an existing one, I want the editor to appear with two rows. The top row is the text field and check box. The second row is the combo box.
Is this possible? I just tried it and I see my combo box appear, but it appears the height of the editing area is fixed, so only my combo box shows up and the text field is no longer visible?
Here is my code:
publicclass AdminTreeCellEditorextends DefaultTreeCellEditor
{
privatefinal JCheckBox activeBox =new JCheckBox("Active");
privatefinal JComboBox revenueCategoryBox =new JComboBox();
privatefinal JLabel iconLabel =new JLabel();
privatefinal JPanel editorPanel =new JPanel(new BorderLayout());
private Icon editIcon =null;
public AdminTreeCellEditor(JTree tree)
{
super(tree, (DefaultTreeCellRenderer) tree.getCellRenderer());
editorPanel.add(activeBox, BorderLayout.EAST);
editorPanel.setOpaque(false);
activeBox.setOpaque(false);
editIcon =new ImageIcon(getClass().getResource("/edit.gif"));
}
public Component getTreeCellEditorComponent(JTree tree, Object value,boolean isSelected,boolean expanded,boolean leaf,int row)
{
Component c = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
SortableTreeNode dmtn = (SortableTreeNode)value;
if (dmtn.getUserObject()instanceof CorporateItem)
{
CorporateItem ci = (CorporateItem)dmtn.getUserObject();
activeBox.setSelected(ci.isActive());
}
else
{
activeBox.setSelected(true);
}
editorPanel.add(c, BorderLayout.WEST);
if (dmtn.getUserObject()instanceof CorporateSpecial)
{
editorPanel.add(revenueCategoryBox, BorderLayout.SOUTH);
}
JTextField jtf = (JTextField)editingComponent;
jtf.setSelectionStart(0);
jtf.setSelectionEnd(jtf.getText().length());
jtf.requestFocus();
// set icon to renderers icon
editingIcon = editIcon;
return editorPanel;
}
publicboolean isCellEditable(EventObject event)
{
boolean retValue = super.isCellEditable(event);
if (retValue)
{
SortableTreeNode dmtn = (SortableTreeNode) tree.getSelectionPath().getLastPathComponent();
if (dmtn.getUserObject()instanceof LowItem)
{
retValue =false;
}
}
return retValue;
}
In the above, if the user object is a CorporateSpecial, I add the combo box to the editor panel. So, it seems to work, accept that the height of the tree node editing area doesn't expand enough to show two rows of items. Is there some call I need to make on the tree for the editing path to set it's height? Can this be done? I am trying to avoid doing a pop-up dialog for editing... I like the idea of the inline node editing.
Thanks.

