JTable - selecting the content of a cell
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Simon_Clarke
Posted On:   Thursday, October 4, 2001 06:30 PM

I have a JTable that my user will be moving through. I want them to highlight the content of a cell as soon as they arrive at the cell (so that what they type will overwrite the cell content). The cells contain dollar values and I am using a customized version of DefaultTableCellRenderer that users a NumberFormat to display the cell correctly. I am also using um.filteredtext.JNumberTextField classes as a DefaultCellEditor to ensure that the user can only type in valid currency amounts. I could really do with a simple piece of code that provides the appropriate display and editing of a dollar value but am having a hard time finding it. I can make do with what I h   More>>

I have a JTable that my user will be moving through. I want them to highlight the content of a cell as soon as they arrive at the cell (so that what they type will overwrite the cell content).


The cells contain dollar values and I am using a customized version of DefaultTableCellRenderer that users a NumberFormat to display the cell correctly.


I am also using um.filteredtext.JNumberTextField classes as a DefaultCellEditor to ensure that the user can only type in valid currency amounts.


I could really do with a simple piece of code that provides the appropriate display and editing of a dollar value but am having a hard time finding it.


I can make do with what I have though, I really want to find out how to select the cell content as soon as the user arrives at the cell.


Thanks for any help.

   <<Less

Re: JTable - selecting the content of a cell

Posted By:   Anonymous  
Posted On:   Tuesday, December 4, 2001 07:14 PM

Let me share my experience - just discovered the method recently.



I use a sub-class of JTable, where I override the editCellAt() method.



First, do a super.editCellAt(), and store the boolean result. The super method initialises the appropriate cell editor component.



Next, get the cell editor component using getEditorComponent. Check whether it is an instance of JTextField. If it is, invoke selectAll() on it.



Finally, return the boolean result from the super call.

About | Sitemap | Contact