JTree in a JTable

Does any one know how to put JTree (or JList) in table cell? I created TreeRenderer that extends JTree and implements TableCellRenderer. But table trims my tree and only one node is visible, and I need all of them.
[221 byte] By [JAntona] at [2007-11-27 5:12:37]
# 1
try this http://java.sun.com/products/jfc/tsc/articles/treetable1/index.htmlregardstestalucida
testalucidaa at 2007-7-12 10:33:41 > top of Java-index,Desktop,Core GUI APIs...
# 2
You need two things.First you need a TableCellRenderer that returns :(JComponent)valueAnd you allthough need a TableCellEditor that returns the JTree when you will edit the table.If you want more information give a hintMessage was edited by: Olek
Oleka at 2007-7-12 10:33:41 > top of Java-index,Desktop,Core GUI APIs...
# 3

In this tutorial Jtree occupates whole column, but I need a new Tree in any cell of the table.

I know, I need to implement Renderer, and I did.

Like this :

class TreeRenderer implements implement TableCellRenderer { /* bla-bla */}

And my tree was rendered, but the height of the cell did not change and only first tree node (that feets the cell size) was rendered. As far as I know you cannot change the height of a single row or cell in the JTable. And I think this problem is.

Does any one know, may be there is some addon labrary, based on Swing, that can solve this problem?

JAntona at 2007-7-12 10:33:41 > top of Java-index,Desktop,Core GUI APIs...
# 4

There is a method to set the rowheight of a single row in a JTable.

table.setRowHeight(int row, int height)

The JTable didn't know if you click on a node in your tree so you need a TreeWillExpandListener to set the right height.

public void treeWillExpand(TreeExpansionEvent tep) {

/* set the rowheight of the clicked tablerow depending on the nodes that will displayed after the treeexpansion*/

// same in treeWillCollaps()

}

But without a TableCellEditor that returns the JTree nothing works.

two methods are important :

private JTree tree;

// some other code ...

// Object during editing

public Component getTableCellEditorComponent(JTable table, Object value,

boolean isSelected, int row,

int column) {

tree = (JTree) value;

return tree;

}

/**

* returned the object after editing

* @return Object

*/

public Object getCellEditorValue() {

return tree;

}

this should solve the problem

Message was edited by:

Olek

Message was edited by:

Olek

Oleka at 2007-7-12 10:33:41 > top of Java-index,Desktop,Core GUI APIs...
# 5
It works, thanks!
JAntona at 2007-7-12 10:33:41 > top of Java-index,Desktop,Core GUI APIs...