• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextArea LineNumbers and colored Text

 
Paul Horner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys and girls,
I want to ask, if I use a JTextArea and want to show the user the actual line number, how should i code this?
And is it possible, to mark a whole line in the JTextArea red
or so?
lg Paul
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think hole line was a misspelling; I shall correct it.

Have you been through the Java™ Tutorials? I am not sure you can do it with a text area; have you tried an editor pane? There is an example in that tutorials “trail” with red text; that may help you. It appears to use a text pane.
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the Text Component Line Number to display line numbers.

You can use a "Highlighter" to highlight the background of the text. Check out the "getHighlighter()" method of the JTextArea.

You may also want to take a look at the Line Painter class. It will highlight the line where the caret currently is.

If you want to highlight the actual text, then you would need to use a JTextPane.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!