Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setValueAt() method in AbstractTableModel

 
Burak Can
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone. I'm about to finish my project so this is the last step. I need to implement the setValueAt() method to my table model which extends AbstractTableModel but even if I went through the JTable API and looked into many setValueAt() implementation example, I couldn't figure out one for my table model. My table reads and writes from/to a txt file. Here is my table model:



(I use setter/getter for Client)

Now I need a setValueAt() method for this model. Since I'm new to java, any kind of help will be appreciated. Thank you in advance.
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { is mirror to getValueAt required fireTableCellUpdated(rowIndex, columnIndex); as notifiers
 
Burak Can
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for quick reply. I always start with public void setValueAt(Object aValue, int rowIndex, int columnIndex) { already but I don't know what to write inside. I know that I need to add fireTableCellUpdated(rowIndex, columnIndex); but I don't know what to write before. And when I try to implement a way similar to getValueAt(), such as:


it doesn't work. Any other suggestions?
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pseudocode based on your AbstractTableModel




better could be to define getColumnClass and (wrap code ) to test if is passes



 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
m Korbel wrote:

The list.get() returns an object here and not an array. So, the above usage is wrong.


Burak,
The setValueAt implementation will be similar to getValueAt. In that method, you check for the column number and then invoke the corresponding 'getter' method on it. Similarly, in the setValueAt, you have to invoke the setter methods. If you are using switch(case) on the columnNumber, do remember to use the break statement!
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ranganathan Kaliyur MannarThe list.get() returns an object here and not an array. So, the above usage is wrong.

- you would need to post an SSCCE demonstrated you issue with

- disagree with hammer for simple things, why to loop, use the case int:, otherwise there are few side effects that limited reusable of XxxTableModel, problably you meaning (with hardcoded ColumnClass)

(again only pseudocode)




- you can to returns ColumnIndex - if (columnIndex[b] == int && aValue instanceof String/*real class from getColumnClass*/) {[/b]
 
Iona Martin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setvalue () method can be used to set the values.Getvalue() can be used to get the values .Pseuodocode canno be used in this method.Switch() function can be used to avoid this method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic