A Jtable implementation
I would like to implement a JTable which will only be edited and updated programatical开发者_如何学Goly. I dont want user interaction enabled.
Firstly the input will be from an array of string elements(after filling the array from a String split).
I then want to set the fields with the array data.
How are the column names stored as Final or whatever for the table life?
Do I need to implement a TableModel if I dont want interaction?
You should probably read through the Java documentation for How to Use Tables.
Things you seem interested in:
isCellEditable()
- Have it return false
means the user can not edit any cells.
getColumnName()
- Look up the name in an array or list of strings.
Regarding editability: use JXTable - it supports layered programatic configuration control. Specifically,
- supports per-column and per-table narrowing (that is, to read-only)
- respects the cell editable property always (that is table.setValueAt does nothing if the cell is not editable)
Yes, the model will be useful but not necessary (also just a DefaultTableModel
).
Actually you could just fill the JTable with static data using the right constructor:
public JTable(Object[][] rowData, Object[] columnNames)
but you won't have any control over the data inside the table.
The model is not used just to provide interaction with editing capabilities but to provide a data source for the table either to read either to write, that's why it's always good to have one.
精彩评论