Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes setValueAt() method in AbstractTableModel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "setValueAt() method in AbstractTableModel" Watch "setValueAt() method in AbstractTableModel" New topic
Author

setValueAt() method in AbstractTableModel

Burak Can
Greenhorn

Joined: Jul 18, 2013
Posts: 5
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

Joined: Jun 19, 2012
Posts: 154
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { is mirror to getValueAt required fireTableCellUpdated(rowIndex, columnIndex); as notifiers
Burak Can
Greenhorn

Joined: Jul 18, 2013
Posts: 5
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

Joined: Jun 19, 2012
Posts: 154
pseudocode based on your AbstractTableModel




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



Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

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!

Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 154
@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

Joined: Jun 02, 2013
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setValueAt() method in AbstractTableModel
 
Similar Threads
jtable, table model, column headers
Display a list in a JTable
How to color JTable cell without a renderer?
JTable Dynamic - Urgent
How do I get selected rows that have a check against them using check boxes in a table