Swing JTextPane编译错误

时间:2013-01-06 15:37:52

标签: java swing user-interface compiler-errors

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package texteditor;
//import java.awt.*;
import javax.swing.*;
/**
 *
 * @author 
 */
public class TextEditor {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        JFrame window = new JFrame("Text Editor");
        //JMenuBar menuBar = window.getJMenuBar();

        //Create menu bar
        JMenuBar menuBar= new JMenuBar();
        //File Menu
        JMenu fileMenu = new JMenu("File");
        fileMenu.add(new JMenuItem("Save"));

        menuBar.add(fileMenu);
        window.setJMenuBar(menuBar);

        JTextPane textArea= new JTextPane();

        Document d= textArea.getDocument();

        window.add(textArea);

        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setVisible(true);
    }
}

错误

Exception in thread "main" java.lang.RuntimeException: Uncompilable
source code - cannot find symbol   symbol:   class Document  
location: class texteditor.TextEditor   at
texteditor.TextEditor.main(TextEditor.java:33) Java Result: 1 BUILD
SUCCESSFUL (total time: 2 seconds)

如何解决?

2 个答案:

答案 0 :(得分:3)

Document中使用的JTextPane包含在单独的text包中。添加导入:

import javax.swing.text.Document;

答案 1 :(得分:1)

线程“main”中的异常java.lang.RuntimeException:无法编译的源代码 - 找不到符号符号:class Document

您需要导入一个名为Document的适当类。

相关问题