我需要在 GUI 中同步 PDF 列表项和 JTextArea 的行距。我可以通过调整其中之一来做到这一点。
在列表项(或 JTextArea)超过一行(在 JTextArea 中将换行设置为 true)之前,这一切都运行良好。
我可以调整两个列表项之间的高度。该距离也将应用于单个多行列表项的两行之间的高度。
然而,在我的 GUI 中,由于 JTextArea 中的组件和默认行间距,这两者并不相同。差异约为一个像素,但如果规模较大,可能会累积并导致一些问题。
那么,有什么方法可以在 JTextArea 中设置行距,或者有什么方法可以区分两个列表项和同一列表项的两行之间的间距?
我完全准备使用任何类型的外部库以及可能需要的任何技巧......
要覆盖 JTextArea 的行间距,请查看 PlainView(用于呈现 PLAinDocument)。
中有以下几行public void paint(Graphics g, Shape a)
method
drawLine(line, g, x, y);
y += fontHeight;
因此您可以调整渲染固定 y 偏移。
In the BasicTextAreaUI
创建视图的方法。将其替换为您自己的实现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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)