How to ensure that text is rendered to fit in tree?

北战南征 提交于 2019-12-24 09:39:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!