Yossale
Yossale

Reputation: 14361

Swing - Search text within a JTextField

I have a documents that's displayed in a non-editable JTextField , and I want to enable users to search within this document.

I already figured out I could use a custom JTextField for input , and use the HighLight painter to mark the occurrences - But I couldn't help but feeling that this seems like such a common problem that maybe there's a component that does it much better then I can (like cycling through the results, highlighting them in different colors , ignoring case...)

Do you know of any such thing?

Upvotes: 3

Views: 816

Answers (2)

dogbane
dogbane

Reputation: 274838

The Swing book (by Matthew Robinson and Pavel Vorobiev) has a great chapter on Constructing an HTML Editor Application which shows you how you can implement "Find and Replace".

Upvotes: 2

kleopatra
kleopatra

Reputation: 51535

SwingX comes with complete search support (in a JEditorPane only, sigh: note to myself - how about the other text components?)

Upvotes: 3

Related Questions