my dog learned polymorphism
The moose likes Swing / AWT / SWT and the fly likes JTextArea question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextArea question " Watch "JTextArea question " New topic

JTextArea question

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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?

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
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.
I agree. Here's the link:
subject: JTextArea question
It's not a secret anymore!