简体   繁体   English

JTextArea输出

[英]JTextArea Output

Good Evening, What can I do to have the output from jTExtArea like in the console? 晚上好,如何在控制台中获得jTExtArea的输出? You can see the image how it is, I use .append to show the output in jTextArea Image 您可以看到图像的样子,我使用.append在jTextArea Image中显示输出

Code: 码:

 public void actionPerformed(ActionEvent e) {
        if (e.getSource() == b1) {

            for (int i = 0; i < a.pattern_cnt; i++) {
                for (int j = 0; j < a.T_element_cnt; j++) {
                 System.out.printf("%.3f\t", a.O[i][j]); //console output

                 t1.append(a.O[i][j]+" ");//jtextarea output
                }

                System.out.println();


            }

Set the font to monospaced. 将字体设置为等距。

t1.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

Edit: 编辑:

And add new line in main iteration and use string format. 并在主迭代中添加新行并使用字符串格式。

        for (int i = 0; i < a.pattern_cnt; i++) {
            for (int j = 0; j < a.T_element_cnt; j++) {
             System.out.printf("%.3f\t", a.O[i][j]); //console output

             t1.append(String.format("%.3f\t", a.O[i][j]));//jtextarea output
            }

            System.out.println();
            t1.append("\n");

        }

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

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