我要问的问题就是JEditorPane的setPage()和setText交替使用,无效的问题。下面是一个小程序,拷到eclipse里直接可以运行的,2个按钮,来回点,几下就不好使了,各位试试。
我找了很多资料,有很多人问这个问题,但我始终没有找到解决方法,请各位csdn的高手帮帮我吧。
附:validate()也不好使、setPage()两次也不好使,还有个File f什么的,取得文件路径的方法也不好使。import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;public class hi extends JFrame{
public hi(){
setBounds(100, 100, 500, 500);
JPanel panel1=new JPanel();//面板一,用来显示网页内容的


String path ="http://www.baidu.com"; final JEditorPane editorPane=new JEditorPane();
JScrollPane jsp1=new JScrollPane(editorPane);


try {
editorPane.setPage(path);
} catch (Exception e) {
// TODO: handle exception
}
panel1.add(jsp1);
add(panel1,BorderLayout.CENTER);

JPanel panel2=new JPanel();//面板二,用来添加按钮的
JButton jb1=new JButton("本地文件baidu.htm");//把百度网页另存为,到c盘根目录
JButton jb2=new JButton("你好!");

jb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e1){
try {
editorPane.setPage("file:///c:/baidu.htm ");
} catch (Exception e) {
e.printStackTrace();// TODO: handle exception
}

}
});
jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e1){
try {
editorPane.setText("你好");
} catch (Exception e) {
e.printStackTrace();// TODO: handle exception
}

}
});

panel2.add(jb1);
panel2.add(jb2);

add(panel2,BorderLayout.SOUTH);
}
public static void main(String a[]){
hi t1=new hi();
t1.setVisible(true);
}
}