Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
Table Model :
As we know in MVC
architecture Model holds the data, and the methods to manipulate
that,
in same manner the JTableModel also holds the
table data, and the methods like
setValueAt(), isCellEditable() ,
getRowCount() etc., which manage that data.
public class
YourAppDefaultTableModel extends DefaultTableModel {
public
YourAppDefaultTableModel(Object[][] rowData, Object[] columnNames)
{
super(rowData,columnNames);
}
public
YourAppDefaultTableModel(Object[][] rowData, Object[] columnNames,
boolean hasHeader) {
super(rowData,columnNames);
this.hasHeader = hasHeader;
}
public
Object getValueAt(int row, int col)
{
int rowIndex =
row;
if (indexes != null
&& indexes.length > 0 &&
row < indexes.length)
rowIndex =
indexes[row];
return
super.getValueAt(rowIndex, col);
}
public void
setValueAt(Object value, int row, int col)
{
int rowIndex = row;
if (indexes != null
&& indexes.length > 0 &&
row < indexes.length)
rowIndex =
indexes[row];
super.setValueAt(value, rowIndex, col);
}
public boolean isCellEditable(int row, int
col) {
return false;
}
public void setDataValue(Object[][] data, JTable
table){
this.dataVector =
convertToVector(data);
int col1,
col2;
col1 =
table.convertColumnIndexToModel(0);
col2 = table.convertColumnIndexToModel(1);
fireTableDataChanged();
}
public void
setDataValue(Object[][] data) {
this.dataVector = convertToVector(data);
}
}
JTable :
JTable table = new JTable(new YourAppDefaultTableModel());
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.