我有一个问题文本窗格。我需要用指定的颜色标记文本的某些部分,因此我决定使用 JTextPane 和 html 标签来装饰我的文本。 JTextPane 位于 JScrollPane 内部,JScrollPane 位于 JSplitPane 内部:
JTextPane jtp=new JTextPane();
jtp.setContentType("text/html");
JScrollPane scr=new JScrollPane(jtp);
JSplitPane leftRight=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scr, someOtherComponent);
另外,将文本设置为jtp我注意到它包裹不正确。
那么,您能否建议我如何解决我的问题,或者提供更好的解决方案?
我使用 html 装饰文本:
<FONT style="BACKGROUND-COLOR: yellow">next marked</FONT><b> embolden</b> normal<FONT style="BACKGROUND-COLOR: yellow"> next marked</FONT>
也许还有其他 Swing 组件可以帮助完成如此简单的文本装饰?
附言这是我的代码的一部分:
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
它根本不包裹。