CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 1999
    Location
    Belarus, Minsk
    Posts
    44

    JTable: Preventing cell from being edited.

    I've got created JTable, and I'd like to prohibit cell's editing (make all cell read-only). How can I do this? Please, help!

    Thanks in advance,
    SY, SkyM


  2. #2
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: JTable: Preventing cell from being edited.


    isCellEditable() method of TableModel has to return false.

    Try this ..



    class CalendarTableModel extends AbstractTableModel{
    String[] m_tColumnName = {"A" ,"B" , "C" , "D" , "E" , "F" , "G" };
    int m_nRowCount = 0;
    protected Vector dataVector;

    public CalendarTableModel(){
    dataVector = new Vector();
    setNumRows(6);
    }

    public int getRowCount(){
    return dataVector.size();
    }

    public int getColumnCount(){
    return m_tColumnName.length;
    }

    public Object getValueAt( int nRow , int nColumn ){
    Vector rowVector = (Vector)dataVector.elementAt(nRow);
    return rowVector.elementAt(nColumn);
    }

    public void setValueAt( Object tValue ,int nRow , int nColumn ){
    Vector rowVector = (Vector)dataVector.elementAt(nRow);
    rowVector.setElementAt(tValue, nColumn);

    // generate notification
    fireTableChanged(new TableModelEvent(this, nRow , nRow , nColumn));
    }

    public String getColumnName( int nColumnIndex ){
    return m_tColumnName[nColumnIndex];
    }

    public boolean isCellEditable( int nRow , int nColumn ){
    return false;
    }
    public void setNumRows(int newSize) {
    if ((newSize < 0) || (newSize == getRowCount()))
    return;

    int oldNumRows = getRowCount();
    if (newSize <= getRowCount()) {
    // newSize is smaller than our current size, so we can just
    // let Vector discard the extra rows
    dataVector.setSize(newSize);

    // Generate notification
    fireTableRowsDeleted(getRowCount(), oldNumRows-1);
    }
    else {
    int columnCount = getColumnCount();
    // We are adding rows to the model
    while(getRowCount() < newSize) {
    Vector newRow = new Vector(columnCount);
    newRow.setSize(columnCount);
    dataVector.addElement(newRow);
    }

    // Generate notification
    fireTableRowsInserted(oldNumRows, getRowCount()-1);
    }
    }
    }





    I dont know a simple solution for this.

    Poochi...


  3. #3
    Join Date
    Jul 1999
    Location
    Belarus, Minsk
    Posts
    44

    Re: JTable: Preventing cell from being edited.

    Thanks for help.


  4. #4
    Join Date
    Oct 1999
    Location
    usa
    Posts
    33

    Can you provide the full source code ?

    can you provide the full source code for a working abstract model ?

    thanks

    http://members.xoom.com/lookads

  5. #5
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: Can you provide the full source code ?


    ????? What's wrong with that code ? That's a fully working code.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured