【发布时间】:2017-05-27 18:55:48
【问题描述】:
我需要字符的绝对位置。与:editorPane.getFontMetrics(f).getAscent()
我只得到到基线的相对距离。也许有办法获得基线的绝对位置?
编辑: 这是rect.y + rect.height - metrics.getDescent() - metrics.getAscent()的结果
【问题讨论】:
-
调用JEditorPane的modelToView方法。
-
ModelToView 不起作用。它为 y 值返回 0。高度就像“世界”二字。我需要单词“Hello”开头的 y 坐标。
-
你需要从视图矩形的底部计算它:
rect.y + rect.height - metrics.getDescent() - metrics.getAscent()(其中rect是modelToView返回的值) -
对不起,它不起作用。上升 + 下降 + 领先 = 高度。它是荧光笔的高度。所以我错过了荧光笔下方的空间。
-
您如何获得用于获取 FontMetrics 的字体?
标签: java swing fonts jeditorpane baseline