jnjsn
May 11th, 2000, 02:46 AM
I want to getSize() of a container, but I couldn't. The methods getSize().width and getSize().height below returned 0 and 0 which were incorrect. Even when I commented out both the button and add() method, they gave the same incorrect result. Any suggestions? Thanks in advance.
import java.awt.*;
import javax.swing.*;
public class ex2_1 extends JApplet
{
Container cont;
public void init()
{
cont = this.getContentPane();
cont.setLayout(new FlowLayout());
JButton bb = new JButton();
cont.add(bb);
System.out.println("width is "+cont.getSize().width+ "height is "+cont.getSize().height);
}
}
--------------------------------------------------------------------------------
import java.awt.*;
import javax.swing.*;
public class ex2_1 extends JApplet
{
Container cont;
public void init()
{
cont = this.getContentPane();
cont.setLayout(new FlowLayout());
JButton bb = new JButton();
cont.add(bb);
System.out.println("width is "+cont.getSize().width+ "height is "+cont.getSize().height);
}
}
--------------------------------------------------------------------------------