Click to See Complete Forum and Search --> : JTable


May 2nd, 2000, 01:57 PM
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);

poochi
May 2nd, 2000, 04:06 PM
> 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..