Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem of override setLocation of java.awt.Component

 
Mandar Khire
Ranch Hand
Posts: 569
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I create swing program which has 1 JFrame which contain 1 JPanel which contain n no of small JPanels.

When small JPanel set Location i try 2 ways
1st way is as follows:-


and another way is
I declare Point mandarlocation;
& following code replace in above code's setLocation function


So by first way i get very properly result, but when i run 2nd way i got exception stack overflow.
By first way from java.awt.component small JPanel set Location.

/**
* Moves this component to a new location. The top-left corner of
* the new location is specified by the <code>x</code> and <code>y</code>
* parameters in the coordinate space of this component's parent.
* @param x the x-coordinate of the new location's
* top-left corner in the parent's coordinate space
* @param y the y-coordinate of the new location's
* top-left corner in the parent's coordinate space
* @see #getLocation
* @see #setBounds
* @since JDK1.1
*/
public void setLocation(int x, int y) {
move(x, y);
}
/**
* @deprecated As of JDK version 1.1,
* replaced by <code>setLocation(int, int)</code>.
*/
@Deprecated
public void move(int x, int y) {
synchronized(getTreeLock()) {
setBoundsOp(ComponentPeer.SET_LOCATION);
setBounds(x, y, width, height);
}
}


but when i run 2nd way then almost 2500 times it run setLocation function within a program not going in to the java.awt.Component
Can anybody help me to understand why this so?
 
Tony Docherty
Bartender
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because in the second example when the panels are not overlapping you recursively call the setLocation() method rather than calling the super.setLocation() method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic