CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2000
    Posts
    2

    getSize() of a Container

    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);
    }
    }

    --------------------------------------------------------------------------------



  2. #2
    Join Date
    Jan 2000
    Location
    CA, USA
    Posts
    305

    Re: getSize() of a Container

    just try
    this.getSize() rather than
    this.getContentPane().getSize()

    Kannan



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured