Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

determine size of contentPane before setting visible...

843805Jun 19 2006 — edited Jun 21 2006
Hi all--

I was wondering is there a way to get what the size of the contentPane for a JFrame will be BEFORE setting it visible?

For instance,
import javax.swing.*;
import java.awt.*;
 
public class MyFrame extends JFrame{
    public MyFrame(){        
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(new Dimension(1024,768));        
        System.out.println("ContentPane size before vis= "+this.getContentPane().getSize());//prints 0,0
        this.setVisible(true);
        System.out.println("ContentPane size after vis= "+this.getContentPane().getSize());//prints 1016,741
   }
    
    public static void main(String [] args){
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                new MyFrame();
            }
        });        
    }
}
How can I get the fact that it WILL be 1016,741 prior to it actually being set visible?

Thanks!

Message was edited by:
mr.v.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 19 2006
Added on Jun 19 2006
3 comments
447 views