Reputation: 1149
I am using a TextArea in JavaFX to display a string that I drag into the TextArea. Inside the TextArea I want to keep a certain format. That's why I am using the rightPad
function of the org.apache.commons.lang3.StringUtils
library to format my string. Here is the part of my code that formats my string:
CustomClass myObject = (CustomClass) dragboard.getContent(customClassDataFormat);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(myObject.getFirstCode() + "\t\t");
stringBuilder.append(StringUtils.rightPad(myObject.getStatement(), maxLength + 2));
stringBuilder.append(myObject.getLastCode() + "\n");
taextArea.appendText(stringBuilder.toString());
maxLength
is a final int value that is equal to the length of the maximum statement I want to display. This variable is computed correctly and does not change its value, I verified this. I was expecting the strings that I drag into my textarea to be perfectly aligned. Instead, I obtain this:
I realize that the mismatch after the first code is due to me using \t\t
. But even if I leave this out, the statements are not aligned. The middle part varies while it should be equal for each string (that's why I am using rightPad
).
Does anyone know a possible reason for this behavior? Could this be the appendText
function of the textarea that's causing this problem?
Upvotes: 0
Views: 312