我想在JTextArea中打印字符串并正确对齐它们.很难解释所以我会上传我想要实现的屏幕截图.

因此,每行打印的字符串都是从Paper对象打印出来的,该对象具有参数(id,title,author,date,rank).数据从文本文件中读取,并使用loadPaper()函数存储在LinkedList中.
然后displayPapers()函数用于向JTextArea显示Paper对象的内容.displayPapers()如下所示:
/** Print all Paper object present in the LinkedList paperList to textArea */
public void displayPapers(){
// clear textArea before displaying new content
displayTxtArea.setText("");
Paper currentPaper;
ListIterator<Paper> iter = paperList.listIterator();
while(iter.hasNext()){
currentPaper = iter.next();
String line = currentPaper.toString();
if("".equals(line)){
continue;
} // end if
String[] words = line.split(",");
displayTxtArea.append (" "
+ padString(words[0],30)
+ padString(words[1],30)
+ " "
+ padString(words[2],30)
+ " "
+ padString(words[3],30)
+ padString(words[4],30)
+ "\n");
System.out.println(words);
//displayTxtArea.append(currentPaper.toString());
} // end while
displayTxtArea.append(" Total …Run Code Online (Sandbox Code Playgroud)