使用分数宽度绘制可编辑的 JTextComponents?

发布于 2025-01-03 14:23:36 字数 600 浏览 0 评论 0原文

我正在使用 JEditorPane,(当然)当我使用抗锯齿和分数宽度绘制组件时,文本看起来好多了。换句话说:

JEditorPane pane = new JEditorPane() {
    public void paint(Graphics g) {
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        super.paint(g);
    }
}

如果我用静态的、不可选择的文本来执行此操作,它会绘制得很漂亮。然而,一旦我开始在其上拖动选区,我就会在帧和伪像之间出现一些奇怪的抖动。有什么方法可以用分数度量来绘制并避免这种奇怪的情况吗?我也尝试在插入符上设置属性,但没有成功。

I'm working with a JEditorPane, and (of course) the text looks so much nicer when I paint the component using antialiasing and fractional widths. In other words:

JEditorPane pane = new JEditorPane() {
    public void paint(Graphics g) {
        Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        super.paint(g);
    }
}

If I do this with static, non-selectable text, it paints beautifully. However, as soon as I start dragging a selection over it, I get some weird jiggling between frames, and artifacts. Is there any way to paint with the fractional metrics and avoid that weirdness? I tried setting the attribute on the Caret as well with no luck.

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

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

发布评论

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

评论(1

美胚控场 2025-01-10 14:23:36

这个问题似乎很久以前就被作者和 StanislavL 在评论中回答了:

如果将“i18n”设置为 TRUE,则效果不可见。刚刚写了一个
小测试用例。或者,您可以使用
java-sl.com/Scale_In_JEditorPane_GlyphPainter.html 添加您自己的
基于分数的画家。

This question seems to be answered long ago by the author and StanislavL in the comments:

If you set the "i18n" to TRUE the effect isn't visible. Just wrote a
small test case. Alternatively you can use the
java-sl.com/Scale_In_JEditorPane_GlyphPainter.html to add your own
fractional based painter.

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