0
私は単純なファイルリーダーで作業しています。それは.txtファイルを読み込んで出力をフォーマットし、出力をJTextAreaに表示します。何らかの理由で出力が正しく表示されません。私は現在のコードを与えており、次にテキストファイルの内容が続きます。このJTextArea書式設定エラーを修正するにはどうすればよいですか?
コード
public static JTextArea display = new JTextArea();
public static void main(String[] args) {
// GUI
JFrame frame = new JFrame("Haberdasher");
frame.setSize(450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
JPanel container = new JPanel();
container.setLayout(null);
frame.setContentPane(container);
JScrollPane scroll = new JScrollPane(display);
scroll.setBounds(10, 10, 415, 150);
container.add(scroll);
frame.toFront();
frame.setVisible(true);
// Logic
String path = "src//employees.txt";
boolean endOfFile = false;
String output = "Name" + "\t\t" + "Weekly Sales" + "\t\t" + "Weekly Pay" + "\n";
try {
FileReader fr = new FileReader(path);
BufferedReader br = new BufferedReader(fr);
while (!endOfFile) {
String name = br.readLine();
if(name == null) {
endOfFile = true;
} else {
int sale = Integer.parseInt(br.readLine());
if(name.length() >= 16) {
output += name + "\t" + sale + "\t\t" + "300" + "\n";
} else {
output += name + "\t\t" + sale + "\t\t" + "300" + "\n";
}
}
}
br.close();
System.out.println(output);
display.setText(output);
} catch (IOException e) {
System.out.println(e);
}
}
employees.txt内容:http://hastebin.com/ijuyedizil.nginx
予想される出力:http://hastebin.com/epesipatot.nginx
のいずれかの印刷をしないでください名前全体または別のタブを使用する –
印刷している文字列の長さに応じて印刷するタブの数(\ t)を設定する必要があります。 –
期待される出力は何ですか?その整列の問題は問題ですか? – Coder