This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple text selection in JTextArea

 
Frank Truong
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder how, if possible, I can maintain multiple text selection in JTextArea/JTextPane/JEditorPane.

Any hints are very appreciated.

Frank :roll:
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Frank Truong:
I wonder how, if possible, I can maintain multiple text selection in JTextArea/JTextPane/JEditorPane.

Any hints are very appreciated.

Frank :roll:


There might be something in JTextComponent#setHighlighter and Highlighter#addHighlight()

Note: This is just an off the cuff reply as I personally have never tried it.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't possible. In fact, I have yet to meet the first text editor / IDE which does allow for multiple text selections.
 
G Estes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, I'm not sure you are correct. Open a Microsoft Word document (I know, I hate MS too). Now, use the mouse to select the first paragraph. Next, press the Control key and use the mouse to select a second paragraph elsewhere in the document. Do a "Copy" and then open a new Word document and do a Paste. The two paragraphs will show up on the document, but not the unselected portions of the original.

Now, can the current version of the JTextArea do this too? I don't know...but I may spend some time trying it out...
[ July 30, 2008: Message edited by: Gil Estes ]
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the CTRL thing in both a JTextArea and MS Word 2000, and neither could do it. Perhaps MS have added this in a later version.
 
G Estes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am testing in Word 2002, so not that recent of a thing. Haven't tested or tried to code to it in JTextArea. I'm not saying JTextArea is possible, just that there are apps that can do it...

Cheers!
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pretty sure I have got it to work on OpenOffice2.3.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well that explains it. I never met those applications
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Frank Truong:
I wonder how, if possible, I can maintain multiple text selection in JTextArea/JTextPane/JEditorPane.

Ok.
I toyed around and came up with this. Of course this is not fool proof (e.g. it cannot figure out de-selection, but its a start.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic