To override the JTextArea line spacing, look at PlainView (used to render PLainDocument).
The public void paint(Graphics g, Shape a) method has the following lines
drawLine(line, g, x, y); y += fontHeight;
This way you can adapt the y rendering correction y.
In the BasicTextAreaUI method to create a view. Replace it with your own implementation of 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; }
source share