java - JTable Not Updating Data -


for reason, nothing changes jtable when called (this method updates jtable after user submits sql query).

givens: datavector , columnnamesvector verified populated correctly. jtable private class variable.

private void updatedata() {     updatedatavariables();     table = new jtable(datavector, columnnamesvector)     {         @suppresswarnings({ "unchecked", "rawtypes" })         public class getcolumnclass(int column)         {             (int row = 0; row < getrowcount(); row++)             {                 object o = getvalueat(row, column);                  if (o != null)                 {                     return o.getclass();                 }             }              return object.class;         }     }; } 

any ideas?

it's common beginner's fallacy confuse objects reference variables, need understand quite distinct. when call this:

table = new jtable(datavector, columnnamesvector) {..... 

you creating new jtable object , having table variable refer it, this has no effect on jtable object displayed gui, 1 table variable referring previously. you're changing property of reference variable, leaving original object unchanged.

the solution: should not creating new jtable rather should creating new tablemodel , place tablemodel existing , visualized jtable. can change table's model calling setmodel(newmodel) on it.

edit: or wolfcastle noted update existing tablemodel rather create 1 anew.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -