Java Reference
In-Depth Information
As long as this returned Account is not null (line 66), we can make it the
current account (line 67). At that point the display needs to be updated, so we:
1) call our own setStatus() method, to update the upper portion of our
GUI, and 2) tell the table that its data has changed (line 71).
16.7.2.11
A word about the fire...() methods. They are not part of the TableModel
interface definition. Rather, they are part of the AbstractTableModel class.
When a Java class is declared abstract it means that some methods need to be
implemented by those classes that use (extend) this class. An abstract class can
still have lots of intact, completely implemented methods, and that is the case
with AbstractTableModel .
The TableModel interface defines methods for adding and removing lis-
teners. Any implementation of the TableModel interface needs to support
these, and to notify any listeners when a change occurs. Such listeners will re-
ceive a call to their tableChanged() method when such a change occurs. But
it doesn't tell us how such notification is triggered. Moreover, the change event,
when received by the listener, needs to define the extent of the change—just a
single cell? a whole row? a column? all columns? and so on.
The AbstractTableModel provides some methods for us to call when a
change in the data has occurred, methods that will then notify all the registered
listeners (Table 16.1). Moreover, it has different methods depending on the
extent of the change, so that the TableModelEvent , sent to all
TableModelListener s, can be constructed with the appropriate definition of
what has changed.
We used (line 71) the fireTableDataChanged() since the content of
the table will change with a change of accounts, but the structure remains the
same. It is also a handy all-purpose method for you to use if you'd rather not
add the complexity of determining which rows have changed to your code.
Finally, remember that anyone who uses (extends) AbstractTableModel ,
including the DefaultTableModel class, gets these methods for their use.
There are several other interactions that are supported by JTable s, ones
that don't require you to do anything to provide them to your application's
end user. When running the BudgetPro GUI, did you try to drag the column
headings? You can also rearrange and resize columns. This is the default behav-
ior for JTable s. You can turn it off, however, if you want your columns to
be fixed:
Ready, aim, fire!
Search WWH ::




Custom Search