Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

JInternalFrame - search text?

In my application, I display the log file using an JInternalFrame (assume textArea has stuff in it)
A user has requested the ability to ctrl-F in order to search.
Is there another class I can use to do this?


JScrollPane scrollPane = new JScrollPane(textArea);
JInternalFrame internalFrame = view.getDataPanel().createInternalFrame(scrollPane, "Log File");

Open in new window

0
allelopath
Asked:
allelopath
  • 2
2 Solutions
 
Thomas4019Commented:
I dont think there is a built in java component for searching like that. One alternative you could do is write the log to a temporary HTML file. Then auto open the HTML file locally in the users web browser. Then they have all the functionality their web browser has. This would only work for an application and not for applets of course. To write the file i would use PrintStream, and then to open the file i would use java.awt.Desktop.
0
 
objectsCommented:
u can use the following to locate the index of the search string in the text

int index = textArea.getText().indexOf(searchString);

0
 
objectsCommented:
0
 
allelopathAuthor Commented:
Thanks for your replies. I ended up using Thomas4019's suggestion. I used BufferedReader/Writer which reads/writes line-by-line. Based on the contents of the line, I could add html tags, like color, to the line.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now