Loading
JTable and JTableModel

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  JTable and JTableModel ?


Ans)

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());



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

JTable and JTableModel


JTable and JTableModel

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free