Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AWT [StackOverflowException]

 
Thiru Thangavelu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code throws StackOverflowException when executing getPreferredSize(). I know, this is an Error Type which is JVM Error. But why I am getting and how to avoid this?
import java.awt.*;
import java.awt.event.*;
public class Test {
public static void main(String args[]) {
Frame f = new Frame("BorderTest");
BorderLayout bl= new BorderLayout();
Panel p = new Panel(bl);
f.setLayout(bl);
p.add(new Label("Hello", Label.CENTER),
BorderLayout.NORTH);
p.add(new TextArea(), BorderLayout.CENTER);
p.add(new TextField(), BorderLayout.SOUTH);
f.add(p, BorderLayout.SOUTH);
f.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
}
);
f.setSize(200,200);
System.out.println(f.getPreferredSize());
f.setVisible(true);
}
}
Thanks
[ Adjusted title so two AWT threads don't appear to be duplicates ]
[ May 30, 2002: Message edited by: Jessica Sant ]
 
Steven Wong
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The following will work.


Clement
SCJP2
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic