I need to syncronise line spacing of my PDF ListItem and JTextArea in my GUI. I can do it by adjusting one or another.
And it all works great unil a ListItem (or JTextArea) is more than one line long (line wrap is set to true in JTextArea).
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.
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.
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...
To override JTextArea's line spacing take a look at the PlainView (used to render PLainDocument).
There are following lines in the public void paint(Graphics g, Shape a)
method
drawLine(line, g, x, y);
y += fontHeight;
So you can adapt the rendering fixing y offset.
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;
}