Witam wszystkich ;-)
Piszę aplikację bazodanową, która wyniki zapytań (całą tabelę) wyświetla w tabelce stworzonej za pomocą AbstractTableModel. Od dłuższego czasu borykam się z problemem edycji tej tabelki, próbowałem różnych sposobów, ale nadal nie potrafię sobie z tym poradzić. Dokładnie wygląda to tak, że gdy kliknę dwukrotnie w jedną z komórek mogę ją edytować, ale po kliknięciu w inną komórkę lub inny element okna aplikacji, w edytowanej komórce pojawia się poprzednia wartość :-( . Proszę o pomoc, bo sam naprawdę nie wiem jak to rozwiązać, a tak właśnie wygląda moja klasa tworząca model tabelki:
class MyTableModel extends AbstractTableModel
{
public MyTableModel(ResultSet rs) throws SQLException
{
result = rs;
try
{
rsmd = result.getMetaData();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
public int getRowCount()
{
try
{
result.last();
return result.getRow();
}
catch (SQLException e)
{
e.printStackTrace();
return 0;
}
}
public int getColumnCount()
{
try
{
return rsmd.getColumnCount();
}
catch (SQLException e)
{
e.printStackTrace();
return 0;
}
}
public Object getValueAt(int r, int c)
{
try
{
result.absolute(r + 1);
return result.getObject(c + 1);
}
catch (SQLException e)
{
e.printStackTrace();
return null;
}
}
public String getColumnName(int c)
{
try{
return rsmd.getColumnName(c + 1);
}
catch(SQLException e){
e.printStackTrace();
return "";
}
}
public boolean isCellEditable(int r, int c)
{
return true;
}
private ResultSet result;
private ResultSetMetaData rsmd;
}