Problems with JTextFields
Hey,
I have an applet with a swing jTextField. I set the original text to 'Click "New Game" to begin.' however, after the user clicks 'new game', the text changes to inform the user of the score "Score: 2 to 3" for example. My problem is this: if I drag the cursor over the text to highlight it, the original text always shows up instead of whatever is currently printed there. So, if I try to highlight "score: 2 to 3" I will instead suddenly see "click new game to begin" reappear. Why is that message persisting underneath?
Thanks in advance,
Dave
[579 byte] By [
Dave_Carta] at [2007-11-27 11:30:26]

Well, I suppose that's an option to circumvent the problem as last resort, but I'd rather just have the text that's displayed also be highlighted. I put the applet up on www.geocities.com/glopv2 if you want to see it. After you click a button, the text will change, but if you highlight it -- original again.
Any ideas?
One thought:
What method are you using to change the text in the text field?
setText or append?
If using append and the text field isn't wide enough to show both "click new game to begin" and "score: 2 to 3" you might see behavior like the one you described.
Try using setText instead.
dwga at 2007-7-29 16:33:57 >

Yes agree with Nizzle. If you don't need the user to edit the field why not use a JLabel? It would solve your problems as well as make it seem better constructed. If you chose JTextField for looks, you can easily apply different visual formatting and borders to it so it looks the same or similar.