Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2009
    Posts
    88
    Rep Power
    0

    Default Validating the jtable data on cell

    I have a jtable in which contains 4 columns
    1 max marks
    2 min marks
    3 secured marks
    4 pass/fail
    1 ,2,4 are not editable only secured marks is editable
    on change of secured marks i want to validate marks
    I implemented TableModelListener i am able to get row,column,value etc but it is throwing exception on setValueAt(x,r,4);
    plz help....

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by anilkumar_vist View Post
    I have a jtable in which contains 4 columns
    1 max marks
    2 min marks
    3 secured marks
    4 pass/fail
    Columns should go from 0 to 3 then, right?

    1 ,2,4 are not editable only secured marks is editable
    on change of secured marks i want to validate marks
    I implemented TableModelListener i am able to get row,column,value etc but it is throwing exception on setValueAt(x,r,4);
    plz help....
    A couple of problems:
    1) You're trying to set column 4 when columns go from 0 to 3?
    2) You've got an exception that you're not showing us
    3) You've got a bug in code that you're not showing us..

    How can you expect much help with the limited information you've provided?

  3. #3
    Join Date
    Oct 2009
    Posts
    88
    Rep Power
    0

    Default

    This is my code and the text with red color that situation me exception
    public void changeData(TableModelEvent e){
    status=3;
    try{
    int row=e.getFirstRow();
    if(e.getType()==TableModelEvent.UPDATE){
    TableModel tm=(TableModel)e.getSource();
    int secured = Integer.parseInt(tblMarks.getModel().getValueAt(ro w, 3).toString());
    int marks = Integer.parseInt(tblMarks.getModel().getValueAt(ro w, 2).toString());
    int maxMarks = Integer.parseInt(tblMarks.getModel().getValueAt(ro w, 1).toString());

    if (secured >= marks) {
    try{
    tm.setValueAt("P",row,4);
    }catch(Exception ex){}

    }
    else {
    try{
    tm.setValueAt("F",row,4);
    }catch(Exception ex){}
    }
    tblMarks.setModel(tm);
    }
    }catch(Exception ex){
    errMsg.setText("Invalid Number");

    }

    }
    Last edited by anilkumar_vist; 10-13-2010 at 01:22 PM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    What exception are you getting, with stack traces?

    Of course if this is actually your code then you are eating exceptions so you won't be able to give us that info.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Similar Threads

  1. JTable Cell Merg
    By anilkumar_vist in forum AWT / Swing
    Replies: 8
    Last Post: 04-25-2011, 09:32 AM
  2. Validating Jtable
    By anilkumar_vist in forum Advanced Java
    Replies: 1
    Last Post: 11-24-2009, 02:54 PM
  3. Jtable and cell coordinates
    By rattaman in forum AWT / Swing
    Replies: 2
    Last Post: 11-17-2009, 05:48 PM
  4. jtable cell renderer
    By ankitmcgill in forum New To Java
    Replies: 2
    Last Post: 05-22-2009, 01:08 AM
  5. Color cell in JTable
    By ippacciani in forum AWT / Swing
    Replies: 3
    Last Post: 03-25-2009, 11:53 AM

Posting Permissions

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