2012-04-17 37 views
1

基本上我有一個名爲FlowLayout.html的文件,我想將它讀入JEditorPane。我有所有的代碼,但我不知道如何打開窗格中的文件。如何讀取JEditorPane中的HTML文件?

JEditorPane jtfInfo = new JEditorPane(); 
    jtfInfo.setEditable(false); 
    p3.add(jtfInfo); 

    public void getFlowLayout(){ 
    jftInfo.setContentType("text/html"); 
    //I dont know this step and setContentType gives me an error in netbeans Cannot find symbol 

}

+0

*」setContentType在netbeans中給我一個錯誤不能找到符號「*在方法上,或'jftInfo'?該方法肯定存在。 – 2012-04-17 08:04:52

回答

3

您只需撥打setPage()方法與URL指着FlowLayout.html文件:

public void getFlowLayout(){ 
    jftInfo.setPage(new URL("path to file")); 
} 

Java Tutorial: How to Use Editor Panes and Text Panes

「的setPage方法打開URL指向的資源,並找出文本的格式(在考試中是HTML) PLE)。如果文本格式是已知的,那麼編輯器窗格使用在URL處找到的文本初始化它自己。標準編輯器窗格可以理解純文本,HTML和RTF。請注意,該頁面可能異步加載,這將保持GUI響應,但意味着您不應該在調用setPage返回後指望數據完全加載。「

+0

好的,謝謝,我會嘗試 – Robert 2012-04-17 01:09:57