How to set and highlight text in JTable cell on selection and/or invoke cell editor directly.

N

news.rcn.com

I have a JTable whose cells display values derived from the data in the
TableModel (rather than the the data itself.)

When a cell is selected (by mouse or keyboard navigation) I need to
1) show the raw data from the table model (not the derived data)
2) highlight it to show it will be replaced after editing.
This needs to be done before the user types into the cell.

I can't figure out how to catch an event when a table cell is selected. My
best guess is to is overide the 'isCellEditable' in the table model and try
to get the cell renderer, then get the Component that draws it.
and load the raw data and select it. However, I could not get this to work.

Alternatively, if I could the cell editor directly when the table cell gets
selected, I could load the raw data in there and let the user have her way
with it. Can I do this? It seems that nobody cares about the editor until
the table cell gets a keystroke typed into it; then the editor UI takes over
the table cell real estate (from the renderer).

I'd appreciate any help or suggestions. Thanks in advance.

jim cant
(e-mail address removed)
 
C

Chris Smith

news.rcn.com said:
I have a JTable whose cells display values derived from the data in the
TableModel (rather than the the data itself.)

When a cell is selected (by mouse or keyboard navigation) I need to
1) show the raw data from the table model (not the derived data)
2) highlight it to show it will be replaced after editing.
This needs to be done before the user types into the cell.

I can't figure out how to catch an event when a table cell is selected. My
best guess is to is overide the 'isCellEditable' in the table model and try
to get the cell renderer, then get the Component that draws it.
and load the raw data and select it. However, I could not get this to work.

Instead of this, why not just implement the cell renderer to return the
desired look for a selected component? The cell will be re-rendered
when it is selected, after all.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top