File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply 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: 482
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.
If you understand, say "understand". If you don't understand, say "don't understand". But if you understand and say "don't understand". How do I understand that you understand? Understand!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1154
    
    3

Because in the second example when the panels are not overlapping you recursively call the setLocation() method rather than calling the super.setLocation() method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem of override setLocation of java.awt.Component
 
Similar Threads
For loop problem
overlapping problem of jpanels
problem with moving a JWindow
Where i make mistake?
3 questions regarding JPanel.