简体   繁体   English

JTextArea不符合控制台的output

[英]JTextArea not in line with the output of the console

I have a question regarding the format in a JTextArea .我对JTextArea中的格式有疑问。

I read in a txt file.我读了一个txt文件。

The output format in the Eclipse console look pretty good. Eclipse 控制台中的 output 格式看起来还不错。 But the output in the text area is bad.但是文本区的output是坏的。

How can that be?怎么可能?

public static void fill_up() {
    String datei = "/home/dirk/BMW/TEST.TXT";
    File file = new File(datei);
    
     if (!file.canRead() || !file.isFile())
            System.exit(0); 
     
     BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(new FileInputStream(datei), StandardCharsets.ISO_8859_1));
            String zeile;
            
            while ((zeile = in.readLine()) != null) {
                text1.append(zeile + "\n");
                System.out.println(zeile);           
            }
                   
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in != null)
                try {
                    in.close();
                } catch (IOException e) {
                }
        } 
     
}
}

Console Output控制台 Output

Text Area文本区

The output format in the Eclipse console look pretty good. Eclipse 控制台中的 output 格式看起来还不错。 But the output in the text area is bad.但是文本区的output是坏的。

How can that be?怎么可能?

The Eclipse console (like most consoles) uses a monospaced Font . Eclipse 控制台(与大多数控制台一样)使用等宽Font This allows each space character to be exactly the same width as each visible letter and aid alignment of the last column.这允许每个空格字符与每个可见字母的宽度完全相同,并帮助最后一列的 alignment。 Change the text area to use a monospaced font and it will align as expected.将文本区域更改为使用等宽字体,它将按预期对齐。

Having said that, this task calls for a JTable - which is well suited to displaying tabular data.话虽如此,此任务需要一个JTable - 它非常适合显示表格数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM