如何确保将文本渲染为适合树状显示? [英] How to ensure that text is rendered to fit in tree?

查看:66
本文介绍了如何确保将文本渲染为适合树状显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JTree似乎并没有自动调整其节点大小以适应大小为20+的字体.我尝试调用revalidate(),但这似乎无济于事.节点中的文本垂直显示为压缩"状态,以便剪切字母的顶部和底部.

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.

如何使用大字体并确保使用JTree正确显示它们?

How can I use large fonts and ensure that they are displayed properly with a JTree?

推荐答案

某些LAF(例如WindowsLookAndFeel)设置了一个固定的rowHeight,该行的高度相当随意(例如16px).请确保强制这棵树为每个节点动态计算高度:

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);

或根据树的字体计算rowHeight并将其设置为固定高度.

or calculate the rowHeight based on the tree's font and set that as the fixed height.

这篇关于如何确保将文本渲染为适合树状显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆