swing-highlighter

Set hilighting color in jTextField

↘锁芯ラ 提交于 2019-12-29 01:27:59
问题 I am developing a Java Swing application. This app allows user use basic command line. For example user can add event with simply type add "Something to be added." .I wanna highlight add when user type this command. Can any one implement a jTextField. 回答1: An idea would be to use a StyleDocument and DocumentFilter This is actually based on this question, but I wasn't sure if I could attempt to use a JTextField import java.awt.Color; import java.awt.EventQueue; import java.awt.GridBagLayout;

JTextPane highlighting issue

一个人想着一个人 提交于 2019-12-18 03:46:43
问题 The last days I have been trying to implement a highlighting feature in a small text editor. For some reason I get a strange result: The given example should highlight each "dolor" - the first occurences are correctly found and highlighted but the next ones aren't. Here is the code I wrote so far: import java.awt.Color; import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing

Highlight backgroung colors of some words in HTML Document in java

≡放荡痞女 提交于 2019-12-13 02:56:37
问题 I am reading HTML document as text and extracting matched strings(with start and end index) from documents based on string array.Now i have to change the background color of those extracted strings in the original HTML document.But i should not change the format of HTML file. so i am using "javax.swing.text.DefaultHighlighter.DefaultHighlightPainter", which will not change the format of document.After highlighting, i am saving file locally, then view in browser to see the colors.I dont want

How to highlight a single word in a JTextArea [closed]

早过忘川 提交于 2019-12-06 07:39:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I want to read in text the user inputs and then highlight a specific word and return it to the user. I am able to read in the text and give it back to the user, but I cant figure out how to highlight a single word. How can I highlight a single word in a JTextArea using java swing? 回答1: Use the DefaultHighlighter

Removing Highlight from specific word - Java

笑着哭i 提交于 2019-12-04 04:22:29
问题 I want to build one sample to remove highlight from words that matches the filter of my app. Therefore I was basing myself on the sample below: public void removeHighlights(JTextComponent jTextArea) { Highlighter hilite = jTextArea.getHighlighter(); Highlighter.Highlight[] hilites = hilite.getHighlights(); for (int i = 0; i < hilites.length; i++) { if (hilites[i].getPainter() instanceof TextHighLighter) { hilite.removeHighlight(hilites[i]); } } } This sample works to remove all highlights of

How to get highlighted text in a jtextarea

99封情书 提交于 2019-12-02 04:15:36
问题 I have a jtextarea with some texts. I use java highligher to highlight some texts on that jtextarea. I want to print the content of that textarea to another textarea with the highlighted texts. Is that possible? Or is there any way of getting only the highlighted text inside a jtextarea? 回答1: Use the getHighlights() method of your Highlighter. From there, you can retrieve the offsets of the start and end of highlighting. 回答2: You can just ask the text area for the selected text using the

How to get highlighted text in a jtextarea

ε祈祈猫儿з 提交于 2019-12-02 01:23:10
I have a jtextarea with some texts. I use java highligher to highlight some texts on that jtextarea. I want to print the content of that textarea to another textarea with the highlighted texts. Is that possible? Or is there any way of getting only the highlighted text inside a jtextarea? Use the getHighlights() method of your Highlighter. From there, you can retrieve the offsets of the start and end of highlighting. You can just ask the text area for the selected text using the getSelectedText method. 来源: https://stackoverflow.com/questions/6360017/how-to-get-highlighted-text-in-a-jtextarea

ColorHighlighter on JXTreeTable - Change selection color if predicate is true

萝らか妹 提交于 2019-12-02 00:01:55
I'm using an JXTreeTable with several ColorHighlighters to change the background color of the rows that include a specific value. If a row is selected, the color will change to SelectionBackground. Is it possible to change the selection background color based on the predicates or color highlighters without an complete new renderer? EDIT: If a row is selected and has an highlighting, ther should be another background color as on a row where is no highlighting. SSCCE package testing; import java.awt.Color; import java.awt.Component; import javax.swing.JFrame; import javax.swing.JScrollPane;

Changing color of selected text in jTextPane

冷暖自知 提交于 2019-12-01 22:57:10
I am creating a text editor using a JTextPane that allows the user to change the color of selected text. But when the user selects the text, then chooses the option to change the color (say, to red) the text does not appear as red until the text is unselected. I tried using setSelectedTextColor to change the color of the selected text, but that doesn't work since that changes the text to red anytime text is selected afterwards. Is there a way to have selected text show up as it's actual color? Or like the way it works in Word where it's not the actual color of the text, but when text of

Removing Highlight from specific word - Java

丶灬走出姿态 提交于 2019-12-01 21:17:28
I want to build one sample to remove highlight from words that matches the filter of my app. Therefore I was basing myself on the sample below: public void removeHighlights(JTextComponent jTextArea) { Highlighter hilite = jTextArea.getHighlighter(); Highlighter.Highlight[] hilites = hilite.getHighlights(); for (int i = 0; i < hilites.length; i++) { if (hilites[i].getPainter() instanceof TextHighLighter) { hilite.removeHighlight(hilites[i]); } } } This sample works to remove all highlights of the Text Area. For example, if I have three selected words and I uncheck the box of one, all of the