I know we have to use AWT thread for all table model update operations. Under the single AWT thread, any table model will be thread-safe. Why DefaultTableModel picks thread-safe Vector as its data stucture, which slower than other data structures like ArrayList?
Constructs a DefaultTableModel and initializes the table by passing data and columnNames to the setDataVector method. The first index in the Object[][] array is the row index and the second is the column index.
The JTable is used to display and edit regular two-dimensional tables of cells.
The TableModel interface specifies the methods the JTable will use to interrogate a tabular data model. The JTable can be set up to display any data model which implements the TableModel interface with a couple of lines of code: TableModel myData = new MyTableModel(); JTable table = new JTable(myData);
We can remove a selected row from a JTable using the removeRow() method of the DefaultTableModel class.
Swing first appeared before Java 1.2, so before ArrayList
was available. Unfortunately, the API for DefaultTableModel
exposes the fact that it uses Vector
, so changing it now would be backwardly incompatible.
This is exactly the kind of reason for thinking about encapsulation carefully - it lets you change the internals later on. (Admittedly getting serialization right would have been interesting, but that's a story for another day...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With