Java 我最近改成了JTextPane,我的加载功能已经中断

Java 我最近改成了JTextPane,我的加载功能已经中断,java,swing,netbeans,loading,jtextpane,Java,Swing,Netbeans,Loading,Jtextpane,“我的加载”功能要求我附加文本窗格 这是我当前的加载特性 private void loadFile() { String line; File file; JFileChooser dialog = new JFileChooser(); if (dialog.showOpenDialog(text) == JFileChooser.APPROVE_OPTION) { file = dialog.getSe

“我的加载”功能要求我附加文本窗格 这是我当前的加载特性

private void loadFile() {
        String line;
        File file;
        JFileChooser dialog = new JFileChooser();
        if (dialog.showOpenDialog(text) == JFileChooser.APPROVE_OPTION) {
            file = dialog.getSelectedFile();
            try {
                 try (BufferedReader input = new BufferedReader(new FileReader(file))) {
                     text.setText("");
                     line = input.readLine();
                     while (line != null) {
                       text.append(line + "\n");
                       line = input.readLine();
                     }
                }
            } catch (IOException e) {
                JOptionPane.showMessageDialog(text, "Can't load file "
                        + e.getMessage());
            }
        }
    }
问题是附加部分,我找不到修复方法。GUI更新代码(如
text.setText(“”;
)应该在GUI线程(EDT)中运行,而CPU耗时的代码(如
line=input.readLine();
)应该在后台线程中运行。阅读更多关于Java的信息,并阅读本Java教程:

GUI更新代码(如
text.setText(“”;
)应在GUI线程(EDT)中运行,而CPU耗时代码(如
line=input.readLine();
)应在后台线程中运行。阅读更多关于Java的信息,并阅读本Java教程:

GUI更新代码(如
text.setText(“”;
)应在GUI线程(EDT)中运行,而CPU耗时代码(如
line=input.readLine();
)应在后台线程中运行。阅读更多关于Java的信息,并阅读本Java教程:

GUI更新代码(如
text.setText(“”;
)应在GUI线程(EDT)中运行,而CPU耗时代码(如
line=input.readLine();
)应在后台线程中运行。阅读更多关于Java的信息,并阅读本Java教程:


再次使用JTextComponent的
read(…)
方法,因为这会将文本文件直接读取到文本组件中

try (BufferedReader input = new BufferedReader(new FileReader(file))) {
    text.read(input, "Text File");
} catch (IOException exp) {
    exp.printStackTrace();
}

再次使用JTextComponent的
read(…)
方法,因为这将把文本文件直接读取到文本组件中

try (BufferedReader input = new BufferedReader(new FileReader(file))) {
    text.read(input, "Text File");
} catch (IOException exp) {
    exp.printStackTrace();
}

再次使用JTextComponent的
read(…)
方法,因为这将把文本文件直接读取到文本组件中

try (BufferedReader input = new BufferedReader(new FileReader(file))) {
    text.read(input, "Text File");
} catch (IOException exp) {
    exp.printStackTrace();
}

再次使用JTextComponent的
read(…)
方法,因为这将把文本文件直接读取到文本组件中

try (BufferedReader input = new BufferedReader(new FileReader(file))) {
    text.read(input, "Text File");
} catch (IOException exp) {
    exp.printStackTrace();
}

哪个是错误消息?@LucasZ.:JTextPane没有
setText(…)
方法。哪个是错误消息?@LucasZ.:JTextPane没有
setText(…)
方法。哪个是错误消息?@LucasZ.:JTextPane没有
setText(…)
method。错误消息是什么?@LucasZ:JTextPane没有
setText(…)
method。