在 JavaFX 2 中计算单行文本尺寸
为了定位自定义光标,我需要能够计算给定字体的单行字符串的尺寸(宽度、高度和基线)。
在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.