Q: I've written a custom TreeCellRenderer for
a JTree . When
using the Aqua look and feel, cells do not render properly
if their label exceeds a single line of text. Only the first
line is shown. What gives?
A:
You need to call setRowHeight(0)
on the JTree you are using. A value of 0 or less for the
JTree.rowHeight property forces the
JTree to consult your custom TreeCellRenderer for the appropriate
size of each row. Without this explicit call, a default
value greater than zero is by used by the JTree without consulting
the renderer.
The call to setRowHeight() should
be made at any point where the JTree could have its updateUI()
method called, which includes:
- Immediately after instantiation
- After changing the look and feel
The real problem behind this issue - which also occurs on
Windows machines when using the Windows look and feel - is
more complicated and involves a known bug in the Javasoft
database, which is exploited by the custom borders of TextField s
used in many custom look and feel's. Metal's lack of a TextField
border makes the problem dormant when choosing that particular
look and feel.
[Nov 02 2001]
|