This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to refresh the JTable description row? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to refresh the JTable description row?" Watch "How to refresh the JTable description row?" New topic
Author

How to refresh the JTable description row?

Sean Gildea
Ranch Hand

Joined: Jul 01, 2004
Posts: 81
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!


SCJD, SCBCD, SCJP
Clivant Yeo
Ranch Hand

Joined: May 22, 2004
Posts: 124
Hi Sean,

Use fireTableRowUpdated() instead.

Regards,
Clivant


Clivant Yeo
My Personal Website
Sean Gildea
Ranch Hand

Joined: Jul 01, 2004
Posts: 81
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

Joined: May 22, 2004
Posts: 124
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

Joined: Jul 01, 2004
Posts: 81
Thanks Clivant,

But that is not my primary problem.

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


Clivant Yeo
Ranch Hand

Joined: May 22, 2004
Posts: 124
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

Joined: Jul 01, 2004
Posts: 81
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

Joined: Oct 08, 2004
Posts: 63
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

Joined: May 22, 2004
Posts: 124
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

Joined: Jul 01, 2004
Posts: 81
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

Joined: May 22, 2004
Posts: 124
Glad that you had sorted it all out. Congrats!
 
GeeCON Prague 2014
 
subject: How to refresh the JTable description row?