Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

My JTable is not refreshing.

 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There:
I am refreshing each time JTable when search matches dabase records. For example, if user selects carrier as SpeedyAir and Origin as 'SFO', there will be only three matched records. So, it will display only three records in the table. If user selects carrier as 'All' and Origin as also 'All'. Table will be covered with all the records from database. So far so good. Most of the time it works. Table gets refreshed. It does not like seldom. I have to try to resize the application window to see refreshed table.
It is weird. I am burned. Anyone have this problem? I will appriciate any response. Thank you. -Bal
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us your basic code for refreshing the JTable. I haven't seen this problem yet. Anyone else?
Mark
 
Rajesh Matti
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bal - JTable is a listener to the TableModel, getting notified when the data changes. I guess, you would have forgot to fire the tablechanged event, when you refresh the rows of your tablemodel. Did you use/extend DefaultTableModel or you have your own implementation ?. For now, you may want to call JTable.repaint(), that should work. But the proper way would be firing events in the tablemodel. The reason why you are seeing the correct data when you resize the screen is the JTables clipped region is invalid and hence it does a painting.
Hope this help,
-Rajesh
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rajesh for your exapalnation. Nop, I did not use TableModel but I used AbstractTableModel. MyTableModel extends AbstractTableModel that is a separate class and separate file. Do I have to register any TableModelListener? Once we have JTable object we get all table listener functionality. Don't we? I am not sure.
I have processTable() method inside my FBNClient class. Whenever processTable() method is called it creates JTable object and repaints. Normally it is called when Search button is pressed. Only one time at the beinning of the program processTable() method is called to display all the record as default value. That is it.
Hello MARK Thanks for asking the code. Here we go:
Most of the time it works. No problem, I do not have to do anything. Some time it does not, What a crook!. But you know what! behind the scene it is working just it cannot display refreshed contents. If I try to resize the application window, Bang...I see the refreshed table contents. what is going on I do not know.
It is killing me. -Bal
[ February 06, 2002: Message edited by: Bal Sharma ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well what I did was I created a Panel that held the JTable. In that JPanel I added a method called getTable() it returned the JTable.
I then created a new instance of my FlightTableModel this extended AbstractTableModel just like you did. then did a setModel on it passing the new instance of FlightTableModel.


In this case I always created a new instance. Almost like yours
I never called repaint though.
Maybe it's the repaint. Maybe that resets the width of columns. I don't know a guess.
Hope that helps, even though I am not sure if I said anything.
Mark
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark I will try it. -Bal
 
Rajesh Matti
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bal - Please make sure that in your 'MyTableModel' you do notify the listeners by 'firing' events, as JTable is a listener to the tablemodel. you may want to call flightTable.inValidate() / flightTable.repaint() after the setModel call. Let me know.
-Rajesh
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure I will try and let you know.
-Bal
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bal
I used my own tablemodel "MyTableModel" witch extends the "AbstractTableModel" in this class you have some JTable "utility" methods, one of them is:

Hope this helps
/Ren�
[ February 07, 2002: Message edited by: Rene Larsen ]
 
Reshma Das
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i made my window non resizable .
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i made my window non resizable
Is this a good choice? I am kind of cunning now. If examiner has only 13" monitor at home and trying to test my application. I developed in 19" monitor in windowsME box. Will I get screw up? I do not know, I am sick of it now.
Thanks Ren� coming to this thread. Bal is lazy. Lazy got a big problem. I do not know how to handel it. It does not get refreshed seldom but not always.
You know what I observed funny behavior. I cannot say it is SUN's bug. It is Bal's bug. When table does not like to refresh. Below from the displayed record turns into gray color. I think this symtom develoed after I added invalidate and tablefire event method. Does this give me any clue?
I hope it is not WindowME problem . Thanks guys for any clue.
-Bal
 
Rajesh Matti
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Toolkit.getDefaultToolkit().getScreenSize(), set your windows size to that. As far as you have used layouts properly, you are fine.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bal
The default background color in an empty JTable is grey, and this will be the color you are seen.
e.g.:
The search retuned two records - two rows in the JTable - with a white background and the rest of JTable is grey..
/Ren�
[ February 08, 2002: Message edited by: Rene Larsen ]
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:
I fixed JTable not refreshing problem. I admit it is my bad. I think I did not clarify you guys clear picture. I was doing live update in JTable. It was the problem. I deleted live update portion from MyModelTable, it works fine. I reread instruction it was not needed.
Thanks Rajesh and Ren� for your help.
By the way Rajesh what do you mean by “As far as I have used layouts properly, I am fine"? Am I missing some thing here? My top-level layout is BorderLayout. Lables and combo box are in a Jpanel as boxPanel it uses GridLayout. Jtabel is also in Jpanel as tablePanel. It also uses GridLayout. All buttons are again in Jpanel as buttonPanel uses GridLayout too. Finally boxPanel is BorderLayout.NORTH, tablePanel is in BorderLayout.CENTER and buttonPanel is in BorderLayout.SOUTH. I wanted to make application as simple as possible, I have not used Grid Bag layout. Do you think? Is there any problem? If we resize application window, how should it behave? What SUN examiner expects to see when resize the window? please let me know.
Thanks in advance for response. -Bal
 
Rajesh Matti
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bal - You are fine with your design. I can see more problem if 'Null Layout' is used or a GridBag layout whose compoenets are improperly constrained , is used.
-Rajesh
[ February 10, 2002: Message edited by: Rajesh Matti ]
 
Hansjoerg Wingeier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you change your content of the table model,
then it is necessary to fire the appropriate
events. A JTable register itself as listener to
the model, so when it receives an event from the
model, it takes care by its own of repainting.
example code:

e.g. calling fireTableStuctureChanged() even updates the names of the columns (not necessary for FBN application, but useful if wanna display different tables).
Cheers
Hansjoerg
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic