• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jtable fire event question

 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
My question when I send new data to the Jtable I am using abstractDataTable extending..
Nothing changes in the table when I send to dataInfo[] to constructor. How do I change the JTable on the fly..
Thanks Lisa
 
Anil Sadineni
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lisa,

After sending the information to your TableModel, invoke repaint method on your JTable object.
I think it will help you.
Bye
Anil
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sir,
It worked also called to table.setModel(model); it works too. but intially my column headers are adjusted and look good, I dynamically create the column header from the file but when I call repaint or table.setModel(model) it throws of my columnheaders.
I have the setPerferredWidth() used on each column but how can i retain my original columnHeader preset size when updating Jtable???
Thanks Lisa
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try
table.sizeColumnsToFit(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
 
Debajyoti Pathak
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try setting the datavector to the new values in DataInfo[] and then do a fireTableDataChanged.

 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks to the both of you and a little tweaking the problem is resolved.
Thanks alot Lisa
 
Nito Raj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Lisa,
How do you make a call to repaint() works?
I passed the dataInfo to my tableModel and called fireTableDataChanged();
public TablePanel(){

model = new FlightTM();
table = new JTable(model);
model.addTableModelListener(this);
pane = new JScrollPane(table);
add(pane);
}
then in tableChanged(TableModelEvent){
table.repaint();
}
but it's not working for me. I checked in the tableChanged method that my table model returns the value according to the dataInfo. However, after I call the repaint(), nothing happened, no new data reloaded. Can you tell me what's trick?

Thanks in advance!
Nito
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nito,

Try this with your code instaed of repaint();
public TablePanel(){
model = new FlightTM();
table = new JTable(model);
model.addTableModelListener(this);
pane = new JScrollPane(table);
add(pane);
}
then in tableChanged(TableModelEvent){
//table.repaint();
table.setModel(model); //comment out repaint and try this
}
Good Luck
Lisa
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic