jtextpane doesn't wrap text

血红的双手。 提交于 2019-11-30 20:08:46

问题


I've got a problem with JTextPane. I need to mark some parts of text with specified color, so I've decided to use JTextPane and html tags to decorate my text. JTextPane is inside JScrollPane, and JScrollPane is inside JSplitPane:

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

Also, after setting text into jtp I've noticed that it wraps uncorrectly.

So, could you advice me how to solve my problem, or, maybe offer a better solution?

I have decorate the text using html:

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

maybe there are any other swing components that helps do such simple text decoration?

P.P.S. Here is part of my code:

    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);

After input text into originalTextArea it doesnt wrap at all.

来源:https://stackoverflow.com/questions/6329967/jtextpane-doesnt-wrap-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!