swing-highlighter

JTextPane highlighting issue

徘徊边缘 提交于 2019-11-29 02:45:11
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.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultHighlighter;

Set hilighting color in jTextField

余生长醉 提交于 2019-11-28 13:02:29
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. MadProgrammer 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; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextField;

How to change highlighting color in Java Swing TextArea? And also, change the beginning of text corresponding to the highlighting location

戏子无情 提交于 2019-11-26 19:04:44
Problem 1: BY using defaulthighlighter, I can make the focused lines change to blue. Now I want to change it to other colors. Do anyone know how to change this parameter? --- solved Problem 2: pos is the beginning index of my substring which I want to highlight. I use setCaretPosition(pos); to update the showing content. But it always appears at the bottom of the window. I want to have it at the top. Could anyone tell me how to deal with that? I use one demo to show my problem: import java.awt.Color; import java.net.MalformedURLException; import javax.swing.JFrame; import javax.swing

How to change highlighting color in Java Swing TextArea? And also, change the beginning of text corresponding to the highlighting location

和自甴很熟 提交于 2019-11-26 06:47:44
问题 Problem 1: BY using defaulthighlighter, I can make the focused lines change to blue. Now I want to change it to other colors. Do anyone know how to change this parameter? --- solved Problem 2: pos is the beginning index of my substring which I want to highlight. I use setCaretPosition(pos); to update the showing content. But it always appears at the bottom of the window. I want to have it at the top. Could anyone tell me how to deal with that? I use one demo to show my problem: import java