有没有办法在jtextarea中应用wysiwyg?

时间:2012-05-07 04:22:22

标签: swing

我正在尝试将我的系统信息(从dos命令“systeminfo> sysinfi.txt”获取)放在JTextarea中。该命令的输出在文本文件中完全匹配,但是当我将其添加到jtextarea时,它就会被扰乱。

有没有办法在JTextarea中使用wysiwyg?

代码:

Process proc = Runtime.getRuntime().exec ("systeminfo ");
BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while ((line = input.readLine()) != null)
{
 jTextArea1.append("\n"+line);
}

1 个答案:

答案 0 :(得分:0)

这是一个SSCCE给我WYSIWYG,

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class TestTextarea {

    public static void main(String[] args) {

        String line;
        JFrame frame = new JFrame();

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JTextArea textArea = new JTextArea();
        textArea.setEditable(false);


        try {
            Process proc = Runtime.getRuntime().exec("systeminfo ");

            BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            while ((line = input.readLine()) != null) {
                textArea.append("\n" + line);
            }

        } catch (IOException e) {
            System.out.println("Exception :" + e.getMessage());
        }

        JScrollPane scrollPane = new JScrollPane(textArea);

        frame.add(scrollPane);
        frame.setSize(500,500);
        frame.setVisible(true);

    }
}