explicitly mtm.fireTableDataChanged()
this is my Listener for button usun
a do this action when i push it :
usun.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (ktoryRow!=-1)
{
try
{
s.executeQuery("delete from plyty where idplyty ="+ktoryRow+"
update plyty set idplyty=idplyty-1 where idplyty>"
+(ktoryRow-1));
dodawanie();
mtm.fireTableDataChanged();
}
catch(Exception eg)
{
System.out.println(eg.getMessage());
}
}
}
});
and this is my function dodawanie(), which i call when i want to get new
data from database
public void dodawanie()
{
try
{
ResultSet r8 = s.executeQuery("select count(*) from plyty");
while (r8.next())
{
liczbaPlyt = r8.getInt(1);
}
dane = new String[liczbaPlyt][4];
ResultSet r1 = s.executeQuery("select idplyty,nazwa,opis,dostepna
from plyty");
int n1 = 0;
while(r1.next())
{
dane[n1][0] = temp.toString(r1.getInt(1));
dane[n1][1] = r1.getString(2);
dane[n1][2] = r1.getString(3);
dane[n1][3] = temp.toString(r1.getInt(4));
n1++;
}
/* for (int i=0;i<10;i++)
for(int j=0;j<4;j++)
System.out.print(" "+dane[i][j]); */
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
//mtm.fireTableDataChanged();
}
jonck@vanderkogel.net - 04 Feb 2005 10:51 GMT
In the API docs, look up fireTableRowsDeleted, this does what you want.
Regards, Jonck
Andrew McDonagh - 05 Feb 2005 11:34 GMT
> explicitly mtm.fireTableDataChanged()
> this is my Listener for button usun
[quoted text clipped - 64 lines]
> //mtm.fireTableDataChanged();
> }
Thats the problem. You are using a DefaultTableModel which stores the
data the JTable is displaying. You are then changing some other model
and asking the DefaultTableModel to inform others it has changed - when
in fact it hasn't. Your other model has.
spark - 06 Feb 2005 11:56 GMT
hmm i dont know if i understood you well
u wrote me that i`m changing some other model.Which other model?? I wrote
another class, this time i extends AbstractTableModel and it looks like this
and the problem is the same:
public class MojaTable extends AbstractTableModel
{
Object[][] values = null;
String[] columnNames = null;
private int columns = 0;
private int rows = 0;
private Integer temp;
public MojaTable(){
pobierzDane();
}
public void pobierzDane()
{
try
{
ResultSet r1 = s.executeQuery("select idplyty,nazwa,opis,dostepna
from plyty");
ResultSetMetaData rsmd = r1.getMetaData();
columns = rsmd.getColumnCount();
columnNames = new String[columns];
for (int i=0;i<columns;i++)
columnNames[i] = rsmd.getColumnName(i+1);
ResultSet r2 = s.executeQuery("select count(*) from plyty");
r2.next();
rows = r2.getInt(1);
int n1 = 0;
values = new Object[columns][rows];
ResultSet r1a = s.executeQuery("select idplyty,nazwa,opis,dostepna
from plyty");
while(r1a.next())
{
values[0][n1] = temp.toString(r1a.getInt(1));
values[1][n1] = r1a.getString(2);
values[2][n1] = r1a.getString(3);
values[3][n1] = temp.toString(r1a.getInt(4));
n1++;
}
for (int i=0;i<rows;i++)
for(int j=0;j<columns;j++)
{
System.out.print(" "+values[j][i]);
if(j==3)
System.out.println("");
}
}
catch(Exception e)
{
System.out.println("funkcja pobierz"+e.getMessage());
}
this.fireTableDataChanged();
}
/**
* @see javax.swing.table.TableModel#getRowCount()
*/
public int getRowCount() {
return rows;
}
/**
* @see javax.swing.table.TableModel#getColumnCount()
*/
public int getColumnCount() {
return columns;
}
/**
* @see javax.swing.table.AbstractTableModel#getColumnName(int)
*/
public String getColumnName(int column) {
return columnNames[column];
}
/**
* @see javax.swing.table.TableModel#getValueAt(int, int)
*/
public Object getValueAt(int rowIndex, int columnIndex) {
return values[columnIndex][rowIndex];
}
}
i create object
MojaTable mtm = new MojaTable();
JTable tablica = new JTable(mtm);
and in function usun if i delete row i call function mtm.pobierzDane()
it isn`t the same model i`m changing??what should i do to change the right
one??
thanks for being patient and help