I am using a JXTreeTable.
I want to show a text in a cell only if the row is collapsed. If the row is expanded the detailed values are shown in the childs so the shortened text in the parent should no longer be visible.
As far as I know this need to be implemented by providing a special ComponentProvider used by the DefaultTableRenderer. Anyhow the CellContext used by the ComponentProvider always indicates that the node is expanded. context.isExpanded() always returns true.
StringValue valueProvider = new StringValue()
{
@Override
public String getString(Object value)
{
return String.valueOf(value);
}
};
ComponentProvider<?> textProvider = new LabelProvider(valueProvider, JLabel.TRAILING)
{
@Override
protected String getValueAsString(CellContext context)
{
System.out.println("Context expanded " + context.isExpanded());
if (context.isExpanded())
{
return "";
}
return super.getValueAsString(context);
}
};
DefaultTableRenderer renderer = new DefaultTableRenderer(textProvider);
What do I have to change in the ComponentProvider to detect if the row of the cell is expanded or not?
The solution can be implemented based on the answer of dic19.
The solution is to implement a special renderer with a
getTableCellRendererComponentmethod that checks for aJXTreeTable. In such a case it is evaluated if the row is expanded. The check for theleafflag may be added also.Unfortunately it is not possible to modify the
DefaultTableRendererbecause the CellContext is not visible in overriding classes.