I got the coding separately for these Line breaking & Tab Spacing.
Line Spacing:
private void drawString(Graphics g, String text, int x, int y) {
for (String line : text.split("\n")) {
g.drawString(line, x, y += g.getFontMetrics().getHeight());
}
}
Tab Spacing:
private void drawtabString(Graphics g, String text, int x, int y) {
for (String line : text.split("\t")) {
g.drawString(line, x += g.getFontMetrics().getHeight(), y);
}
}
How can I combine this codes?
Where I want the out put of g.drawString("Line 1\t:Words\t\nLine 2\t:\tWords", x, y); :
Like;
Line 1 [tab space]: [tabspace] Words
Line 2 [tab space]: [tabspace] Words
Note: embedding the modification of the
yvariable inside the method call makes it confusing. I would separate it into 2 instructions to make the code more obvious:PS: are you sure you don’t want to simply use a JTextArea?