Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java JTextComponents highlighting...

Options
  • 10-01-2003 6:59pm
    #1
    Posts: 0


    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: 0 [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