Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextArea question

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I wonder if there's anyway to (1) press a button (say ctrl-t) and the JtextArea will write a the NAME of the user (NAME=some string prepared in advance).

Currently I have it with a jbutton - but when the user press this button, the NAME is *append* to the jtextArea and not (2) getting in the right place (where the cursor is located).

any idea?

Thanks
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can bind these keys and the corresponding Action to the JTextArea or one of its parent JComponents. The How to Use Key Bindings page in the tutorial shows how to do this.

JTextArea has an insert method that may be useful for adding the name. Also, its superclass JTextComponent has handy methods for moving around in a JTextArea. You can find the JTextComponent methods that apply to JTextArea in the Methods inherited from class javax.swing.text.JTextComponent section of the JTextArea api.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic