Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

table cell values

 
Bhuvan mehra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
please write how can i make table's cell value's editing property false.
thanks.
regards,
bhuvan.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your table model extends AbstractTableModel,
you could override the method below to make any cell non-editable:
public boolean isCellEditable(int row, int col);
 
Bhuvan mehra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sai,
thanks and regards,
Bhuvan.
 
Bhuvan mehra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Sai;
one more problem to JTable. please give your suggestions.
i want to extract selected row's data, which method can help me to achive.
i thought about
x = jtable.getSelectedRow()
do i need to extract data form all cols one by one form x row or is there any method to get as an array.
thanks and regards,
Bhuvan.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like you mentioned, you can get the selected row using the getSelectedRow() method. Once you have the selected row, you can ask your table model by calling model.getValueAt(row,0). Then you can do a find to get all the data from the database.
Or you could create a method in the model to return an Object[] by passing the selected row number.
 
Bhuvan mehra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Sai,
i will try to follow as you said.
please give me your suggestion about one more step.
before presenting result of new search, i am deleteing all rows from table and add new rows.
it's working perfectly. but i am not satisfied with the tech.
i belive there will be inbuilt tech. for this. please give me idea about that.
regards,
bhuvan.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have to delete any records. Update the two dimensional Object array in your table model and fire appropriate methods like:
fireTableCellUpdated(row,col) from setValueAt(row,col) method. I assume you are extending your table model from AbstractTableModel class.
 
Bhuvan mehra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Sai,
thanks and regards,
bhuvan.
 
Bhuvan mehra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Sai,
I thought DefaultTableModel implements all the methods. so I extended DefaultTableModel.But I am not able to update my table. please help

public class MyTableModel extends DefaultTableModel
{
Object[][] data;
public MyTableModel(Object[][] data)
{
this.data = data;
}
public boolean isCellEditable(int row, int col)
{
return false;
}
public void setValueAt(Object[][] value, int row, int col)
{
data = value;
fireTableCellUpdated(row, col);
}

}
client GUI
{
Object tableData[][];
tableModel = new MyTableModel(tableData);
tableFlightInfo = new JTable(tableModel);
}
clientGuiHandeler
{
clientGui.tableData = new Object[dataInfo.length] [];
for(int i=0; i<dataInfo.length; ++i)
clientGui.tableData[i] = dataInfo[i].getValues();
clientGui.tableModel.setValueAt(clientGui.tableData, ?,?);
}

thanks,
regards,
bhuvan.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you override the setValueAt() method, you need to call super.setValueAt() and pass the parameters. Also I don't believe you have to call any of the fire* methods since you extend DefaultTableModel.
 
Bhuvan mehra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Sai,
regards,bhuvan.
 
Bhuvan mehra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Sai,
i am not able to get that when i will call setValueAt(object[][],int row,int col) method from clientGuiHandler(to update Jtable with new rows), what will i pass as row,col in setValuesAt.
when i pass row,col. it only update that particular location of cell and didn't delete old rows.
regadrs,
bhuvan.
[ April 09, 2002: Message edited by: Bhuvan ]
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you are extending DefaultTableModel, you can try setDataVector() method.
Or extend AbstractTableModel and include a method like below:
public void setData(Object[][] newData) {
data = newData;
fireTableDataChanged();
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic