wood burning stoves 2.0*
The moose likes Java in General and the fly likes Why does overridden method get called when class is created Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why does overridden method get called when class is created" Watch "Why does overridden method get called when class is created" New topic
Author

Why does overridden method get called when class is created

Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

Hi All,
Can anyone explain to me why this happens? I have a very simple custom JTable, and I have overridden the getValueAt(int row, int col) method. (Note: My overridden method makes no sense. I am just experimenting here.) What happens when I instantiate my custom JTable is that the getValueAt() method is also called automatically. Why does this happen? Many thanks for your help!!
Barry
Here is the custom JTable:

Here is where I am calling it:
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Barry
It looks like the getValueAt method is being called (maybe by the JVM or by the Frame) when it actually paints/displays the table on the screen.
In the code below I added a static variable to keep track of the nmber of times the getValueAt method is called and it is called each time cell in the table is created/painted.


Then I added this code into your getValueAt method:

every other cell is correct and the others still show the "I am overriding..." String.
so it looks like this is called for each cell as it is displayed.
someone else may know exactly what is going on and can shed more light on it than me...
hope that helps

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform


Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why does overridden method get called when class is created
 
Similar Threads
JTable
JRadioButton in JTable
JTable
JTable
problem in JTable