Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Automatic highlight of text in JTextField?

SnookerLoopySnookerLoopy Member Posts: 41
Hi, can anyone help me with this...

Upon a certain event, I have a JTextField with contents automatically set to "1" by:

textField.setText("1");

I have also put the cursor in this text box automatically with:

textField.requestFocus();

But I would like to know if there was a way that I could set the text I have placed in this box to be automatically highlighted, so the user does not have to delete the "1" before they can re-assign their own value.

Most times, the user will leave it at "1", but just for that extra user-friendliness. Thanks for any help :-)

Comments

  • VilanyeVilanye Member Posts: 684
    : Hi, can anyone help me with this...
    :
    : Upon a certain event, I have a JTextField with contents automatically set to "1" by:
    :
    : textField.setText("1");
    :
    : I have also put the cursor in this text box automatically with:
    :
    : textField.requestFocus();
    :
    : But I would like to know if there was a way that I could set the text I have placed in this box to be automatically highlighted, so the user does not have to delete the "1" before they can re-assign their own value.
    :
    : Most times, the user will leave it at "1", but just for that extra user-friendliness. Thanks for any help :-)
    :


    I don't know how to for sure, but try some of the inherited methods from JTestComponent, like select(), selectAll(), SetHighlighter(),ect.
    [italic][blue]Just my 2 bits[/blue][italic]

  • SnookerLoopySnookerLoopy Member Posts: 41
    : : Hi, can anyone help me with this...
    : :
    : : Upon a certain event, I have a JTextField with contents automatically set to "1" by:
    : :
    : : textField.setText("1");
    : :
    : : I have also put the cursor in this text box automatically with:
    : :
    : : textField.requestFocus();
    : :
    : : But I would like to know if there was a way that I could set the text I have placed in this box to be automatically highlighted, so the user does not have to delete the "1" before they can re-assign their own value.
    : :
    : : Most times, the user will leave it at "1", but just for that extra user-friendliness. Thanks for any help :-)
    : :
    :
    :
    : I don't know how to for sure, but try some of the inherited methods from JTestComponent, like select(), selectAll(), SetHighlighter(),ect.
    : [italic][blue]Just my 2 bits[/blue][italic]
    :
    :

    Thanks Vilanye, I'll give that a go :-)
Sign In or Register to comment.