/*
 * 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)

如何解决?

最佳答案

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

import javax.swing.text.Document;

09-30 19:48