问题
JTree does not seem to automatically resize its nodes to accommodate fonts of size 20+. I've tried calling revalidate(), but that doesn't seem to help. The text in the nodes appears "squished" vertically so that the top and bottom of letters are clipped.
How can I use large fonts and ensure that they are displayed properly with a JTree?
回答1:
Some LAFs (e.g. WindowsLookAndFeel) set a fixed rowHeight which is rather arbitrary (like 16px). Be sure either to force the tree to dynamically compute the height for each node:
tree.setRowHeight(-1);
or calculate the rowHeight based on the tree's font and set that as the fixed height.
来源:https://stackoverflow.com/questions/19224825/how-to-ensure-that-text-is-rendered-to-fit-in-tree