Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes JTable, rowVector, addNotify() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JTable, rowVector, addNotify()" Watch "JTable, rowVector, addNotify()" New topic
Author

JTable, rowVector, addNotify()

fedai gandjaliyev
Ranch Hand

Joined: Dec 05, 2005
Posts: 99
Hello!
Can anybody please help me!
I'm creating a JTable.
JTable table = new JTable();
Vector rows = new Vector();
Vector columns = new Vector()
//specify column names
//add a couple of rows
table.setDataVector(rows, colums);

And I have a method

public Vector createClientElement(String name, String surname, String birthdt, String email, String mobile){

Vector v = new Vector();
v.addElement(name);
v.addElement(surname);
v.addElement(birthdt);
v.addElement(email);
v.addElement(mobile);

return v;
}

This
Vector r = new Vector();
r = createClientElement(name, surname, birthdt, email, mobile);
rows.add(r);
table.addNotify();
works.
This
int selRow = table.getSelectedRow();
rows.remove(selRow);
table.addNotify();
works too.
But this
Vector r = new Vector();
r = createClientElement(name, surname, birthdt, email, mobile);
rows.set(r); // I even tried replacing "set" by removing and then adding an elenment at the same position.
table.addNotify();
does not.
Only after I click somewhere on the table the element is set.
What am I doing wrong?
Waiting for reply.......
Thank you very much!
fedai gandjaliyev
Ranch Hand

Joined: Dec 05, 2005
Posts: 99
So, I guess there is no solution to this problem!
Rodrigo Alvarez
Ranch Hand

Joined: Apr 10, 2006
Posts: 75
looks like a refresh problem

try to validate() the JTable after you setRow()


It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
fedai gandjaliyev
Ranch Hand

Joined: Dec 05, 2005
Posts: 99
Doesnt help!
Here is the code (on a button click)
Vector r = new Vector();
r = createDlvrElement("smth", "smth");
dlvrTabValues.set(0, r);
dlvrTable.addNotify();
dlvrTable.validate();
Even removing and then adding at the same position doesnt work.
If that worked that would do to me.
If I add add or remove before set then it works.
But that is not a solution.
PLEASE HELP!
Thank you
Rodrigo Alvarez
Ranch Hand

Joined: Apr 10, 2006
Posts: 75
Does this work :

((DefaultTableModel) table.getModel()).insertRow(position, zeNewRow) ;

?

The model of a JComponent contains the data displayed by the GUI component.

If you manipulate often the content of your JTable, you might want to do something like this

TableModel zeModel = new DefaultTableModel();
JTable lovelyTable = new JTable(zeModel);

=> you then manipulate the model each time you want to change the content of the JComponent.
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
You need to call the component.updateUI() method after any change of data in your JTable.

It is that simple.
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Here the component is the JPanel or something else which holds your JTable.
fedai gandjaliyev
Ranch Hand

Joined: Dec 05, 2005
Posts: 99
table.updateUI() worked!
Thank you!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTable, rowVector, addNotify()