It does not apply drawString, but in the general case, if you want to print sets of lines formatted in a fixed width, you can simply generate each line as a line by combining the fields there with the required number of spaces between them. The code will look something like this:
String[] makeLines(String[] labels, String[] data, int width){
String[] lines=new String[labels.length];
StringBuilder spaces=new StringBuilder();
for(int i=0;i<width;i++)
spaces.append(" ");
for (int i=0;i<labels.length;i++){
lines[i]=labels[i]+spaces.substring(0,width-data[i].length()-labels[i].length())+data[i];
}
return lines;
}
Edit: as Lawrence Gonçalves pointed out, this only works for fixed-size fonts.
source
share