要覆盖JTextArea的行间距,请查看PlainView(用于呈现PLainDocument).
public void paint(Graphics g,Shape a)方法中有以下几行
drawLine(line, g, x, y);
y += fontHeight;
因此,您可以调整渲染固定y偏移.
在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;
}