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

problem of override setLocation of java.awt.Component

 
Mandar Khire
Ranch Hand
Posts: 565
Android Java Linux
  • 0
  • 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
Pie
Posts: 2878
59
  • 0
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic