• Post Reply Bookmark Topic Watch Topic
  • New Topic

could use some help creating a find & replace dialog

 
Randall Twede
Ranch Hand
Posts: 4520
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is probably the right forum since a lot of this involves JTextComponent.
i am trying to duplicate the find & replace dialog in open office word.
i can't seem to find the right tutorial. i read the oracle tutorial about regular expressions. i am pretty much up to speed with that.
the first problem right now is how do i make the found text selected?
between regular expressions, String, JTextComponent, JTextPane, DefaultEditorKit...i am confused
here is what little i have so far. it won't look like this in the end because i am obviously doing it wrong.

in the meantime i will keep looking. someone must have done this before.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randall Twede wrote:the first problem right now is how do i make the found text selected?

JTextComponent#setSelectionStart(int startIndex) and JTextComponent#setSelectionEnd(int endIndex) though I suspect it not might work for multiple selections with words in between.
You might also want to consider using a Highlighter as documented here (The example might just be what you are looking for)
 
Randall Twede
Ranch Hand
Posts: 4520
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Maneesh, that should be enough to get this stalled part of the project moving again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!