TreeTable Collapse/Expand Buttons

Answered

Hi,

I created a table using TreeTable. But the expand/collapse buttons are not visible in the interface. (But can expand/collapse, only button is not in the interface) I tried many ways to make it appear, but I couldn't. How can I do that?

5 comments
Comment actions Permalink

Please show your code setting up the table

0
Comment actions Permalink

Here are you;

private fun buildOverviewPanel(set: TraceSpanSet): JBScrollPane{
root = set.node()

val model = TraceChartTableModel(root)
val table = TraceChartTable(model) // extend of TreeTableView

table.apply{
autoResizeMode = 4
autoCreateColumnsFromModel = true
rowSelectionAllowed = true

setRootVisible(true)
showsRootHandles = true
columnModel.apply{
getColumn(0).cellRenderer = RENDERER_SERVICE_NAME
getColumn(1).cellRenderer = RENDERER_OPERATION_NAME
getColumn(2).cellRenderer = DurationCellRenderer(set.overallDuration())
}
}

return JBScrollPane(table, 20, 31)
}

The whole table is made with IntelliJ components. I've tried many solutions like this, but nothing has changed; https://intellij-support.jetbrains.com/hc/en-us/community/posts/205965224/comments/205068104

0
Comment actions Permalink

Have you tried to specify TreeColumnInfo for the first column?

Looks like the following code overrides tree-based renderer with the list-based one:

   getColumn(0).cellRenderer = RENDERER_SERVICE_NAME

You have to specify TreeTable#setTreeCellRenderer for a tree column.

Also, I recommend trying JBTreeTable instead.

0
Comment actions Permalink

The following method of your model have to return TreeTableModel.class for the tree-based column:

public Class getColumnClass(int column) {
return (column == 0) ? TreeTableModel.class : String.class;
}

Could you please check it?

0
Comment actions Permalink

(sorry for late answer)

Thanks for your answers. I changed my code according to what you said and tried again, it worked exactly as I wanted it.



A revised version of the code for who has the same problem as me of:

private fun buildOverviewPanel(set: TraceSpanSet): JBScrollPane{
root = set.node()

val model = TreeTableModel(root)
val table = JBTreeTable(model)

table.apply{
tree.apply{
showsRootHandles = true
isRootVisible = true
cellRenderer = CellRenderer()
}
}

return JBScrollPane(table, 20, 31)
}

// Cell Renderer Class
class CellRenderer : ColoredTreeCellRenderer(){

override fun customizeCellRenderer(
tree: JTree,
value: Any?,
selected: Boolean,
expanded: Boolean,
leaf: Boolean,
row: Int,
hasFocus: Boolean
) {
append("your string")
}
}

// Table Model Class -> getColumnClass
override fun getColumnClass(columnIndex: Int): Class<*> = when(columnIndex){
0 -> TreeTableModel::class.java
1 -> String::class.java
2 -> Int::class.java
else -> throw IllegalArgumentException("Column is out of bound. ColumnIndex=$columnIndex")
}



0

Please sign in to leave a comment.