在 JavaFX 2 中计算单行文本尺寸

发布于 2024-12-29 06:39:33 字数 191 浏览 6 评论 0原文

为了定位自定义光标,我需要能够计算给定字体的单行字符串的尺寸(宽度、高度和基线)。

在 Java Swing 中,这是(我似乎记得)通过 Font 上的方法调用完成的,但在 JavaFX 2 中,我发现执行此操作的唯一方法是将文本放入 Label 中并查询标签。

这似乎是一种尴尬的做事方式。有更好的办法吗?

谢谢, 肯

In order to position a custom cursor, I need to be able to compute the dimensions (width, height, and baseline) of a single-line string, given a given Font.

In Java Swing, this was (I seem to recall) done with a method call on Font, but in JavaFX 2, the only way I can discover to do this is to put the text in a Label and query the label.

This seems like an awkward way of doing things. Is there a better way?

Thanks,
Ken

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

第七度阳光i 2025-01-05 06:39:33

JavaFX JIRA 网站上有一个功能请求。所以它尚不可用,但也许值得添加您的投票。

There's a feature request for it on the JavaFX JIRA site. So it's not available yet, but maybe worth adding your vote.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文