• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable, rowVector, addNotify()

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I guess there is no solution to this problem!
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
looks like a refresh problem

try to validate() the JTable after you setRow()
 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to call the component.updateUI() method after any change of data in your JTable.

It is that simple.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here the component is the JPanel or something else which holds your JTable.
 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
table.updateUI() worked!
Thank you!
 
This tiny ad is suggesting that maybe she should go play in traffic.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic