JTextArea:设置大文件内容的文本冻结我的应用程序

时间:2014-05-22 05:09:18

标签: java swing jtextarea filereader event-dispatch-thread

我读取文件并将文本(大小约为4000KB)设置为JTextArea。它冻结了我的申请。以下是我的代码段。我很感激你的建议......

public void setText(final JTextArea textArea)
{
    SwingUtilities.invokeLater(new Runnable()
    {
        public void run()
        {
            BufferedReader from = null;
            try
            {
                from = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
                System.out.println("Started..........");
                textArea.read(from, file.getName());
                System.out.println("Completed..........");
            }
            catch (Exception ex)
            {
                Logger.getLogger(FileTools.class.getName()).log(Level.SEVERE, null, ex);
            }
            finally
            {
                try
                {
                    from.close();
                }
                catch (IOException ex)
                {
                    Logger.getLogger(FileTools.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

        }
    });
}

0 个答案:

没有答案