java - Swing JTextPane编译错误

标签 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)

如何解决?

最佳答案

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

import javax.swing.text.Document;

关于java - Swing JTextPane编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14183669/

相关文章:

java - 更改 JSpinner 大小(宽度)

java - Android:IllegalStateException - 什么时候抛出?

c++ - 为GUI编程实践项目构想?

java - 无法显示超出最大字符数

java - JFrame 程序中的按钮错误

java - 在普通内存和字符串池中创建新字符串

swing - 无法使用 OpenJDK 6 和 7 找到 JButton 类

GIT GUI (Windows) - 从 Unstaged 移动到 Staged

java - 如何为使用 WorkbookFactory 创建的工作簿创建 CellStyle?

java - OWLAPI : Parser not found if run from Jar