1, when we click on the table, first check whether the table is still cell editing, if there is cell editing, then call the editor's Stopcellediting () method, as shown in red in the image.
Note: When editor
be installed to table
There are two chances of calling Celleditor after the
the stopcellediting ()
Method
1
, a cell
is being edited, at this point we clicked with the mouse
"Such an area: the table
within the cell that is being edited
The editor used
of the
Editorcomp
outside of this area. " This will call Stopcellediting ()
Method
2
that directly triggered the cell.
The editor used
of the
Editorcomp
the event. Let's say when we use JTextField
act as editor
of the
Editorcomp
when we hit Enter, the Stopcellediting () will be called directly .
Method
and this article is the first case we are talking about.
2, processing completed the last edit cell, and then go to Method Adjustselection (e), as shown in the green figure
3, in method Adjustselection (e), will determine whether this click can make a cell in the table can be edited. The implementation is in method Table.celleditat (row, column, E), as shown in the following figure
4, and in the method Table.celleditat (row, column, E), but also in the second judge of the current editor is not the end. Specific as follows1) If editor still exists, call Editor's stopcellediting () method, such as red flag. 2) Get the editor used by the cell that is currently being edited, and then get the component that the editor uses to actually edit the data, that is, Editorcomp, and then add the Editorcomp to the table, such as the green tag. This is where we can see that this cell is in an editable state. 3) Register the monitor event with the editor (not Editorcomp) that is now activated. The table itself implements the Celleditorlistener, so we can register the table itself. So when executing the method in editor public boolean stopcellediting (); public void cancelcellediting (); When these two methods call the protected void fireeditingstopped () protected void fireeditin of the editor type Gcanceled (), it is in these two methods, called the method in the listener, that is, the method in table public void editingstopped (ChangeEvent e) public void editingcanceled (ChangeEvent e)5, table inside of editingstopped (ChangeEvent e) method, concrete is such. Get the value in editor and pay this value to the table model. and remove editor . 6, remove the editor. Red flag, remove the listener for this editor, which is the table itself. Green removes the component of editor, which is Editorcomp. Blue Flag, redraw this cell The entire execution process is such that the Celleditor stopcellediting () àcelleditor fireeditingstopped () Àcelleditorlistener (table implements this interface, So table is a Celleditorlistener instance) of editingstopped (ChangeEvent e) Àtablemodel setvalueat () Only when editor is present, will have the opportunity to call Editor's stopcellediting (), and how exactly can make editor appear. This logic is clearly written in the method Table.celleditat (row, column, E). As shown in step 4 ALSO: We use the JDK code is 1.6, so the line number of the screenshot may be inconsistent with 1.4