aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes problem of override setLocation of java.awt.Component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem of override setLocation of java.awt.Component " Watch "problem of override setLocation of java.awt.Component " New topic
Author

problem of override setLocation of java.awt.Component

Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 504

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?


Millions saw the apple fall, but Newton asked why.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2366
    
  50
Because in the second example when the panels are not overlapping you recursively call the setLocation() method rather than calling the super.setLocation() method.
 
 
subject: problem of override setLocation of java.awt.Component