CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: JTable

  1. #1
    Guest

    JTable

    I have a JTable with a column to enter search criteria. The column is editable and filled with empty strings. I enter a value in one of the rows. I see the value in the table, however when I press the Search button and get the value from the table the value is null. If I move to another cell in the table, I get the value when I push the Search button. How can I get the value when I press the Search button without going to another cell first?

    Below is the code to get the value from the JTable:

    String criteriaValue = (String) udiTable.getValueAt(r, 2);



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

    Re: JTable


    > when I press the Search button and get the value from the table the value is null

    It's because you are still in the editing mode in Table. Before you do search , you have
    to update the TableModel with the latest data in the Table. Do the following in your actionlistener of the "Search" Button



    public void actionPeformed( ActionEvent e ){
    if(e.getSource() == ButtonSearch ) {
    TableCellEditor ed = table.getCellEditor();
    if( ed != null ){
    Object obj = ed.getCellEditorValue();
    table.setValueAt( obj , table.getEditingRow() , table.getEditingColumn() );
    }
    // Now do the search Here...
    }

    }




    Another solution is : you can call TableCellEditor.stopCellEditing() before you do Search..

    Poochi..


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