Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java JTextComponents highlighting...

  • 10-01-2003 06:59PM
    #1
    Posts: 431 ✭✭


    Hey all,

    Happy new year, this is my first new year programming post! whoohoo!

    Anyway, I was hoping if someone could venture some help with a java problem of mine.

    I want to have a Java Application running, with a JTextArea or JEditorPane in the middle, and a button.

    My problem is that every time I press the button, I want the text area to highlight that particular line and for the highlight to move to the next line every time I press the button.

    I've been researching this and I've found things using JEditorPanes, StyleConstants and the like.

    But can something like this be done with normal JTextArea?

    Links or sample code would be great, thanks, this problem has been annoying me for a while now.

    Cheers


Comments

  • Closed Accounts Posts: 358 ✭✭CH


    [PHP]
    jTextArea.setCaretPosition( 1 );
    jTextArea.moveCaretPosition( ( jTextArea.getDocument().getLength() - 1 ) );
    jTextArea.selectAll();
    [/PHP]


  • Posts: 431 ✭✭ [Deleted User]


    Thanks, i can see that with that code, I can modify it to highlight only 1 line at a time, move the caret position from the end of the last line, to the lenght of the next line.

    thanks for the help
    :)


  • Closed Accounts Posts: 358 ✭✭CH


    selectAll() is wrong. thats just going to select the whole document.

    what you should be looking at with your selection is JTextComponents setHighlighter or setSelectionColor ( JTextArea inherits from JTextComponents ).

    if you havn't already, look at sun's quick tutorial on this stuff

    gl


Advertisement