The second example here is a search through the text. all you would need to do is read the .txt file and store it as a string. then display it in the text field to search through.
sirlink99
Practically a Master Poster
661 posts since Oct 2010
Reputation Points: 45
Solved Threads: 19
You want each letter to be searched for? or do you want to search multiple words?
The user would enter their word. Then you store the word. Then once the text document opens up you add the variable to the spot. In the example that I showed you you would insert it into the position of s here
hilit.removeAllHighlights();
String s = entry.getText();
if (s.length() <= 0) {
message("Nothing to search");
return;
}
String content = textArea.getText();
int index = content.indexOf(s, 0);
if (index >= 0) { // match found
try {
int end = index + s.length();
hilit.addHighlight(index, end, painter);
textArea.setCaretPosition(end);
entry.setBackground(entryBg);
message("'" + s + "' found. Press ESC to end search");
} catch (BadLocationException e) {
e.printStackTrace();
}
} else {
entry.setBackground(ERROR_COLOR);
message("'" + s + "' not found. Press ESC to start a new search");
}
}
void message(String msg) {
status.setText(msg);
}
You would replace all the s and then it would work like you were searching for it. You could remove some of the code possible, but the idea is the same.
sirlink99
Practically a Master Poster
661 posts since Oct 2010
Reputation Points: 45
Solved Threads: 19