KeyListener to each cell in JTable

Hi !I wanted to add keyListener to "each editable cell" in the JTable.Thanks,Vin
[115 byte] By [aarvin] at [2007-9-26 2:01:59]
# 1

This is not a good strategy. You can only add a KeyListener to a component, and a cell is not a component. You can add it to the entire JTable, but that may not be useful depending on how you intend to use it.

Mitch Goldstein

Author, Hardcore JFC (Cambridge Univ Press)

mdgoldstein@hotmail.com

mitchg at 2007-6-29 8:42:56 > top of Java-index,Archived Forums,Java Programming...
# 2
I guess each cell in JTable is inturn a component like JTextField. When it is possible to render other components in JTable i assumed that adding Listener to these individual components are OK.Thanks for the reply :-)
aarvin at 2007-6-29 8:42:56 > top of Java-index,Archived Forums,Java Programming...
# 3

You can add a key listener to the CellEditor, or a FocusListener etc..

There is one cellEditor (by default) for each column and it is used for

all the rows in the column (so only put one on the editable columns)

JTextField f = new JTextField();

f.addKeyListener(new KeyListener() ....

// Set the click count to 1 for editing in the cell

DefaultCellEditor cell = new DefaultCellEditor(f);

catalogTable.getColumn(YOUR_COLUMN_NAME).setCellEditor(cell);

You could try that IF you need to add a keylistener

hope this helps

lordkilgour at 2007-6-29 8:42:56 > top of Java-index,Archived Forums,Java Programming...
# 4
That worked fine. Even though it holds good for the whole Col it solved my problem.ThanksVin
aarvin at 2007-6-29 8:42:56 > top of Java-index,Archived Forums,Java Programming...