|
-
August 22nd, 2011, 10:01 AM
#1
Highlighting a word in a JTextArea
Hello, I am in need of a solution to solve a problem I am having right now.
The problem is to highlight a word in a JTextArea.
I am able to highlight a single character in the JTextArea by using the code below:
Code:
if (detectionMethod2 == true) {
String chars = "{";
comp = jTextArea1;
charsToHighlight = chars;
Highlighter h = comp.getHighlighter();
h.removeAllHighlights();
String text = comp.getText();
for (int j=0;j<text.length();j++) {
char ch = text.charAt(j);
if (charsToHighlight.indexOf(ch) >= 0) {
try {
h.addHighlight(j, j+1, DefaultHighlighter.DefaultPainter);
} catch (Exception ble) {
}
}
}
}
However, I have no idea how to convert or change the above to ONLY highlight a word that I want. For example, "int" without the quotation marks. It will only highlight the word "int" and nothing else, not even integer or anything that has "int" in it.
Hopefully someone will be able to help me out there. Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|