Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TextArea as TableCellRenderer

69 views
Skip to first unread message

Thorsten Kiefer

unread,
Nov 27, 2009, 5:07:29 AM11/27/09
to
Hi,
I want to use a TextArea as TableCellRenderer.
The problem is when I press "enter", editing is canceled.
And when I use the arrow keys, editing is also canceled.
How can I prevent cancelation.

Best Regards
Thorsten

John B. Matthews

unread,
Nov 27, 2009, 10:27:36 AM11/27/09
to
In article <4b0fa4e1$0$9753$6e1e...@read.cnntp.org>,
Thorsten Kiefer <cyli...@news.cnntp.org> wrote:

> I want to use a TextArea as TableCellRenderer.

I've never tried to use a TextArea in a JTable, but JTextField and
JTextArea work. You'll want a renderer, but you'll also need an editor
to implement TableCellEditor and have it return whichever component you
decide to use:

<http://java.sun.com/docs/books/tutorial/uiswing/components/table.html>

> The problem is when I press "enter", editing is canceled.
> And when I use the arrow keys, editing is also canceled.
> How can I prevent cancelation.

When you click on a JTextField or JTextArea, i.e. when either has focus,
the keys will work according to the defaults specified in the current
look & feel (L&F). You can change a key's binding as desired:

<http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html>

Here's a nice tool for exploring the default key bindings and Action
names found in a particular L&F:

<http://www.camick.com/java/source/KeyBindings.java>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Christian Kaufhold

unread,
Nov 30, 2009, 7:04:20 AM11/30/09
to
Thorsten Kiefer <cyli...@news.cnntp.org> wrote:

> I want to use a TextArea as TableCellRenderer.

TextArea or JTextArea?

> The problem is when I press "enter", editing is canceled.
> And when I use the arrow keys, editing is also canceled.
> How can I prevent cancelation.

That is presumably because the textarea does not get focus, so the
JTable handles these key events instead of the textarea.

If you use *just* a textarea, see
JTable.setSurrendersFocusOnKeystroke
(or similar name)

If you use a textarea in a JScrollPane etc., it gets more complicated.

0 new messages