• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextArea LineNumbers and colored Text

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic