2011-06-13 58 views
0

我遇到了問題JTextPane。我需要用指定的顏色標記文本的某些部分,所以我決定使用JTextPane和html標記來裝飾我的文本。 JTextPane的是裏面JScrollPane的,而JScrollPane的是內部調整JSplitPane:jtextpane不包裹文本

JTextPane jtp=new JTextPane(); 
jtp.setContentType("text/html"); 
JScrollPane scr=new JScrollPane(jtp); 
JSplitPane leftRight=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scr, someOtherComponent); 

此外,設置文本JTP後,我發現它包裝uncorrectly。

那麼,你能告訴我如何解決我的問題,或者,也許提供更好的解決方案?

P.S.我用html來裝飾文字:

<FONT style="BACKGROUND-COLOR: yellow">next marked</FONT><b> embolden</b> normal<FONT style="BACKGROUND-COLOR: yellow"> next marked</FONT> 

也許還有其他的擺動組件可以幫助做這種簡單的文字裝飾嗎?

P.P.S.這裏是我的代碼部分:

originalTextArea=new JTextPane();   
    originalTextArea.setFont(font); 
    originalTextArea.setContentType("text/html"); 
    originalTextArea.setText("dhjfsfdjnkjfgfjkgkjfngfdkjnjfdgjfdngfdkjgnkdngjgnjkgfgf"); 

    processedTextArea=new JTextPane();   
    processedTextArea.setFont(font); 
    processedTextArea.setContentType("text/html");    

    JScrollPane originalTextScrollPane=new JScrollPane(originalTextArea); 

    JScrollPane processedTextScrollPane=new JScrollPane(processedTextArea); 
    JTabbedPane processedTextAndVocPane=new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT); 
    summarizedTextAndVocPane.add("Processed text",processedTextScrollPane); 

    JSplitPane leftRightSplitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, originalTextScrollPane, processedTextAndVocPane); 
    leftRightSplitPane.setDividerLocation(0.5); 
    leftRightSplitPane.setResizeWeight(0.5);   

    mainFrame.add(leftRightSplitPane); 

後輸入文本originalTextArea它沒有在所有

+2

你是什麼意思包裝「包錯誤」 ? – jzd 2011-06-13 11:50:09

+0

我的意思是 - 它根本不包裹我的文字。我不需要水平分割器,我需要將所有文本按jtp的寬度進行包裝。 – stemm 2011-06-13 11:53:37

+3

我用你的代碼做了一個快速測試,它包裝很好。你向我們展示了所有相關的代碼嗎? – Howard 2011-06-13 12:01:08

回答