I have a JTextArea in a JScrollPane with hundreds of lines of text in it. I would like to add a JComboBox with some key words in it and when the user selects one of the key words the scroll pane moves to the first appearance of this word in the text area. Something like search/find in a normal text document.

Is there an easy way to achieve this?

For start you can use String class method indexOf(String str). It will help you find first occurrence and indexOf(String str, int fromIndex) helps with search from index position of currently found/highlighted till end of string if any more exists

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.