Skip to main content

JXTreeTable : String truncated in labels

3 replies [Last post]
elskwi_
Offline
Joined: 2011-01-29
Points: 0

Hello

I use a data model, with labels as renderer into a JXTreeTable. (simply extends DefaultTreeCellRenderer)
I edit an element that has its name displayed, for "exemple MyNode" to "MyVeryLongNode"
Then the tree is updated and shows something like "MyNode..."
After some research, it appears that the trouble is in the BasicTreeUI. This is well explained here :
http://explodingpixels.wordpress.com/2008/06/02/making-a-jtreecellrender...

My first attempt was to force the size of the JLabel Component, with no success...
After reading the source code of BasicTreeUI, it's logical that my first attempts doesn't work :)

So, questions are :
How to find a way to change the BasicTreeUI ?
It seems impossible because the JTree is private and changes are so deep to change it on the fly

Is it possible to force the component to reevaluate the size ?
The BasicTreeUI uses an Abstract Method Factory pattern, nodeDimensions is "lazy" initialized
and it seems impossible to reset the field.
The design of the BasicTreeUI doesn't allow to be modified after it has been initialized...

Is there an other way ?

Thanks for answers

Elskwi

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kleopatra
Offline
Joined: 2003-06-11
Points: 0

in a "normal" tree that's a typical sympton of not notifying the model as needed, f.i. by doing the change on the node (vs. doing it on the model). In a treeTable, that would be my first suspect as well :-)

To nail it, add your model to a plain tree and see what happens.

Cheers
Jeanette

elskwi_
Offline
Joined: 2011-01-29
Points: 0

Hi Jeanette !

Nice to see you again here !

A Jtree provides the same behaviour

The code of BasicTreeUI is formal :
the Preferred Size is used to be cached into a NodeDimensionHandler
@see BasicTreeUI#createNodeDimension

This object prevent the new Preferred Size of the JLabel to be applied.

This is not a problem to override the default behaviour, the problem is how replace it into the default JTree used into JXTree / JXTreeTable.

Or else, I have missed something :)

Elskwi

Edit : I have forced a larger preferred size into the constructor of my TreeCellRenderer, it provides a basic solution.

Edit 2 : super.modelSupport.fireChildChanged(blablabla) works well,
thanks Jeanette
This is strange that the cell editor doesn't do the job after changes.

kleopatra
Offline
Joined: 2003-06-11
Points: 0

don't quite understand where the editor comes into play now :-) And strange indeed, that it doesn't trigger the correct event to be fired ... how about posting a SSCCE, maybe you stumbled across a bug in JXTreeTable (editing might be a bit ... neglected, cough).

Cheers
Jeanette