Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Some Problem with Table  RSS feed

 
Lilyana Saputra
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to using jTable to show my database...
i have been show it using ScrollingResultSetTableModel....

it has been appear into jTable
and i want to delete record that selected ... it can't work..

DATA d;

String cmd="select * from mhs";
d.executeQuery(cmd);
model=new ScrollingResultSetTableModel(d.getResultSet());
jTable1.setModel(model);

int[] selected = jTable1.getSelectedRows();
for (int i=selected.length-1; i>=0; i--)
//model.removeRow(selected[i]);
System.out.println(selected[i]);
for (int i=0; i<jTable1.getRowCount(); i++)
{
if (jTable1.isCellSelected(i, 0))
System.out.println("Select "+i);
else
System.out.println("Not Selected "+i);
}

class DATA is class to connect and execute query...
and process has been always enter to Not Selected and no rows has been detected that it selected....
 
Rajasekar Elango
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How have you implemented your model (ie extending DefaultTableModel or AbstractTableModel)..

if you are changing some data in the model, you have to call model's fireTableDataChanged() for JTable update its view. Also you have to register your JTable as TableModelListener to you model. have a look at addTableModelListener() method of model.

Thanks,
Raja
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what DATA is, or ScrollingResultSetTableModel, but if the code you gave is like this in your application:

In other words, if you execute getSelectedRows immediately after setting the model, it's no wonder that no rows are selected! There's no chance for the user to select any rows. You need to have a button on your GUI with text on it like "delete selected rows", and have the event handler trigger the deletion.

Some users prefer check boxs in rows to select them, rather than directly selecting rows, by the way -- not everyone knows about shift-click...
[ February 14, 2006: Message edited by: Jeff Albertson ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!