Reinstein, Lenny (2002-03-19 23:49):
>I want to achieve this: When the user double-clicks a particular cell
>in the JTable, it becomes editable. What is the easiest way to do it?
>MouseListener listenes to double click, while the isCellEditable in the
> data model determines whether the cell is editable or not. How can I connect
> the two?
>
Have a peek at how TableCellEditors works. It is all supported in there.
Make your custom TableCellEditor if nessecary, then just overide the
isCellEditable(...)
and you should be fine.
Se below for example code:
/**
* Ask the editor if it can start editing using <I>anEvent</I>.
* <I>anEvent</I> is in the invoking component coordinate system.
* The editor can not assume the Component returned by
* getCellEditorComponent() is installed. This method is intended
* for the use of client to avoid the cost of setting up and installing
* the editor component if editing is not possible.
* If editing can be started this method returns true.
*
* @param anEvent the event the editor should use to consider
* whether to begin editing or not.
* @return true if editing can be started.
* @see #shouldSelectCell
*/
public boolean isCellEditable(EventObject anEvent)
{
if (anEvent instanceof MouseEvent)
{
if (((MouseEvent)anEvent).getClickCount() < clickCountToStart)
{
return false;
}
}
// Or check for other thrilling eventchains to happen
// keyboardEvent under 1.2.2 delivers null by some unknown
// reason. Don't know how it works under 1.3 and above.
return true;
}
---
Yours sincerely
Peter Norell
SchlumbergerSema, Sweden
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing