jtextpane不包装文本 [英] jtextpane doesn't wrap text

查看:131
本文介绍了jtextpane不包装文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 JTextPane 的问题。我需要用指定的颜色标记文本的某些部分,所以我决定使用JTextPane和html标签来装饰我的文本。 JTextPane在JScrollPane中,JScrollPane在JSplitPane中:

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

此外,在将文字设置为 jtp 之后我发现它已经包装了不正确。

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?

PS我用html装饰文字:

P.S. I decorate 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?

PPS以下是我的代码的一部分:

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

输入文本到originalTextArea之后它根本不包装

After input text into originalTextArea it doesnt wrap at all

推荐答案

http://java-sl.com/tip_html_letter_wrap .html
这表明如何添加字母换行支持

http://java-sl.com/tip_html_letter_wrap.html That shows how to add letter wrap support

这篇关于jtextpane不包装文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆