1

I'm working on a project that requires having low level control over text that will be displayed in a JTextArea. In my search to understand how this can be achieved I came across Elements. Is there any way using custom Elements that I could get access to the individual words typed into a document? If so, how would I structure these elements?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Chris Grimm
  • 771
  • 6
  • 15
  • you want space separate words of TextArea? – chintan Apr 11 '13 at 04:04
  • Yes. However, I am not interested in reading the entire text every time it is modified and running a regex over it. Rather, I am wondering if it is possible to get what are effectively 'hooks' to the words in the text. That way I could access and modify these words without having a parse the entire body of text. – Chris Grimm Apr 11 '13 at 04:14
  • `jtextArea.getText()` ? – joey rohan Apr 11 '13 at 05:00
  • That isn't what I'm looking for. getText offers up a copy of the entire text contained in the textArea. I'd like to have hooks to individual words without having ever get the entire document's text. – Chris Grimm Apr 11 '13 at 05:13

2 Answers2

2

An instance of javax.swing.text.Element represents a part of a structured Document, the model used by JTextComponent. Elements are not necessarily individual words; they are typically parts of a document that share some common attribute(s). You can see how to traverse the elements of a document in examples shown here and here. See also How to Use Editor Panes and Text Panes.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
2

I'd like to have hooks to individual words

Maybe Document.createPosition()

camickr
  • 321,443
  • 19
  • 166
  • 288