File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to refresh the JTable description row?

 
Sean Gildea
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

Heres my problem:

I solved my problem of data not refreshing in the JTable everytime a new search is done by implementing the following code...



however... The actual description row on the top of the JTable that says "hotel name", "location", ect dissapears frequently after a new search and I have to left click on it to make it reappear. Same with the right hand scroll bar.

Now I know you could make a new JTable, but my mouse listener needs to access an existing one in order to return the correct row, so I cannot create a new JTable each time(atleast I know of no way to do so).

Can anyone lend me some ideas or a solution to my problem?

Thanks in advance!
 
Clivant Yeo
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sean,

Use fireTableRowUpdated() instead.

Regards,
Clivant
 
Sean Gildea
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Clivant,

That still doesnt solve my problem.

My data refreshes fine. Its the column descriptions , the first row basically which doesnt refresh.

Anyone have any ideas how to make it refresh with the data?
 
Clivant Yeo
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sean,



I think you shouldn't put your fireTableXXX method in your getValueAt() method. It is called by your JTable when the JTable repaint itself, but when you execute the fireTableXXX method in your getValueAt() method, you are asking it to repaint itself again when it is trying to repaint itself thus confusing the presentation. If you want to use the fireTableXXX method, use it in another method that is not for the JTable to call. Just my 2 cents.

Regards,
Clivant
 
Sean Gildea
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Clivant,

But that is not my primary problem.

The column holding this data below (description row) doesnt refresh.


 
Clivant Yeo
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sean,

I don't think you need to refresh the column names, they should be the same throughout. Anyway by calling the fireTableXXXX method do not refresh the table column names.

Regards,
Clivant
[ December 10, 2004: Message edited by: Clivant Yeo ]
 
Sean Gildea
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Clivant,

Thank you for your continued responses.

I think you are right, because when I change my method to


it displays the top column, however the data does not refresh everytime a search is done, so I'm back to my original problem.

fireTableCellUpdated(row, col) fixed my data refresh problem, but created the row description display problem.

How can I get my data to display properly everytime I perform a search?
 
Matt Sheehan.
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used the updateUI() method in JTable. I'm not sure if this is the right way to do it, but it worked.
 
Clivant Yeo
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sean,

Hi Clivant,

Thank you for your continued responses.

I think you are right, because when I change my method to

code:


public Object getValueAt(int row, int col) {

Object [] temp = (Object[])hotelListing.get(row);
//fireTableCellUpdated(row, col);
return temp[col+1];
}



it displays the top column, however the data does not refresh everytime a search is done, so I'm back to my original problem.

fireTableCellUpdated(row, col) fixed my data refresh problem, but created the row description display problem.

How can I get my data to display properly everytime I perform a search?

--------------------


Create a method in your AbstractTableModel like this:

public void recordsSearched(Record rec) {
// Add record to underlying storage
storage.add(record);
// refresh your view
fireTableDataXXX;

}

and call this method everytime you have a search. The JTable will refreshed the UIs based on its underlying listeners and it will use the getValueAt() method to find the objects required. Make sure your getValueAt() method can access your storage. Just my 2 cents.

Regards,
Clivant
 
Sean Gildea
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just figured out my problem this morning.

I moved my setup of the JScrollPane out of the refresh method into the panel setup method and then it refreshes perfectly everytime now.

The way I solved it was by looking at Max Habibi's code from his book and seeing how mine was setup.

Took me a month but I figured it out, and I think your help clivant with the fireTableData helped on the refresh end.

thanks again!
 
Clivant Yeo
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad that you had sorted it all out. Congrats!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic