textpane.setPage(ClassLoader.getSystemResource("aaa.txt"));aaa.txt放在classes目录下

解决方案 »

  1.   

    把你的fileDialog换成现成的JFileChooser不好吗?textpane.setPage(fileDialog.getSelectedFile().toURL());
      

  2.   

    老大:只能显示 *.java.不能显示*.txt.....怎么办??是不是用JTextPane不好?要不换个JTestField 或是其他的试一试.
    似乎一定要用到BufferedReader之类的东东......
    把你的fileDialog换成现成的JFileChooser不好吗?请告知怎么换........
    请给出完整源程序好吗,一定重谢........
    目的:用java写一个类似于windows自带的记事本..............
      

  3.   

    写了一个,你看看,另外jdk/demo/jfc下有一个notebook的例子,可以参考
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;public class SplitTest extends JFrame {
    JScrollPane sp = new JScrollPane();
    JEditorPane tp = new JEditorPane();
    JButton btn = new JButton("open");

    public SplitTest() {
    this.setSize(400, 300);
    this.getContentPane().add(sp, BorderLayout.CENTER);
    this.getContentPane().add(btn, BorderLayout.SOUTH);
    sp.getViewport().add(tp, null);
    btn.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    openFile();
    }
    });
        }
        
        public void openFile() {
         JFileChooser ch = new JFileChooser();
    try {
    if (ch.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {  //判断按下的是否是Open按钮
    File file = ch.getSelectedFile();
    if (file != null && !file.isDirectory()) //判断是否选中文件及选中文件是否是文件夹
     tp.setPage(file.toURL());

    }
    } catch(Exception ex) {}
    } public static void main(String[] args) {
    SplitTest frame = new SplitTest();
    frame.setVisible(true);
    }
    }