I have a problem with JTextPane . I need to mark some parts of the text with the specified color, so I decided to use the 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);
In addition, after installing the text in jtp, I noticed that it was not correctly ported.
So, could you advise me how to solve my problem, or maybe offer a better solution?
I 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 some other swing components that help make such a simple text design?
PPS 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 entering text in originalTextArea it does not wrap at all.
stemm source share