iText列表项或JTextArea中的行间距 [英] Line spacing in iText list item or JTextArea

查看:858
本文介绍了iText列表项或JTextArea中的行间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的GUI中同步我的PDF ListItem和JTextArea的行间距。我可以通过调整一个或另一个来做到这一点。

I need to syncronise line spacing of my PDF ListItem and JTextArea in my GUI. I can do it by adjusting one or another.

这一切都很好,一个ListItem(或JTextArea)长度不止一行(换行设置为true)在JTextArea)。

And it all works great unil a ListItem (or JTextArea) is more than one line long (line wrap is set to true in JTextArea).

我可以调整两个ListItem之间的高度。该距离也将应用于单个多行ListItem的两行之间的高度。

I can adjust the height between the two ListItems. That distance will also be applied to the height between two rows of a single multiline ListItem.

但是,在我的GUI中,由于JTextArea中的compononet boreders和默认行间距,那两个不一样。差异大约是一个像素,但是大规模可能会累积并导致一些问题。

However, in my GUI, due to compononet boreders and default line spacing in JTextArea, those two are not the same. Difference is about one pixel, but on large scale that can accumulate and cause some issues.

那么,有什么方法可以在JTextArea中设置linepacing,或者任何方式我可以区分两个列表项和两个相同列表项之间的空格吗?

So, is there any way I can set linespacing in JTextArea, or any way I can differentiate between spaceing between two list items and two rows of the same list item?

我全都使用任何类型的外部库和任何类型的技巧可能需要...

I'm all up for using external libraries of any kind and any kind of tricks it may take...

推荐答案

要覆盖JTextArea的行间距,请查看PlainView(用于渲染PLainDocument)。

To override JTextArea's line spacing take a look at the PlainView (used to render PLainDocument).

公共无效油漆中有以下几行(图形g,形状a)方法

        drawLine(line, g, x, y);
        y += fontHeight;

因此,您可以调整渲染修正y偏移。

So you can adapt the rendering fixing y offset.

BasicTextAreaUI 方法中创建视图。将其替换为您自己的 PlainView实现

In the BasicTextAreaUI method to create view. Replace it with your own implementation of the PlainView

public View create(Element elem) {
    Document doc = elem.getDocument();
    Object i18nFlag = doc.getProperty("i18n"/*AbstractDocument.I18NProperty*/);
    if ((i18nFlag != null) && i18nFlag.equals(Boolean.TRUE)) {
        // build a view that support bidi
        return createI18N(elem);
    } else {
        JTextComponent c = getComponent();
        if (c instanceof JTextArea) {
        JTextArea area = (JTextArea) c;
        View v;
        if (area.getLineWrap()) {
            v = new WrappedPlainView(elem, area.getWrapStyleWord());
        } else {
            v = new PlainView(elem);
        }
        return v;
        }
    }
    return null;
}

这篇关于iText列表项或JTextArea中的行间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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