Get size of a JFrame

I need to get the Width and height of a J frame and pass those 2 integers to a method.  I have attempted this with myFrame.getHeight() but when I try to print the value all I get is a 0.  Can anyone show me what sort of code I should be using for this.

Thanks...
grhs0043Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bobbit31Commented:
make sure the frame is visible before you check getHeight and getWidth
0
grhs0043Author Commented:
It is .... i can see the frame when the program compiles but I cant get the height or width of it.
0
bobbit31Commented:
can you post your code?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

grhs0043Author Commented:
public class mainFrame extends Frame {
JPanel graphPanel = new JPanel();
graphPanel.setEnable(false);  // <--tried this enabled to
graphPanel.setLayout(xYLayout1);
contentPane.add(graphPanel, BorderLayout.CENTEr);

panelHeight=graphPanel.getHeight();   <--panel Height INT
panelWidth=graphPanel.getWidth();     <-- so is panelWidth
graphPanel.add(myGraph, new XYConstraints(0,0,350,350));
}

This is the just of the code.... hopefully it helps...
Any Idea whats wrong.
0
bobbit31Commented:
i'm not sure if you are doing this, but like i said, the JFrame has to be VISIBLE on screen before calling getHeight and getWidth:

public class MainFrame extends JFrame {
   JPanel graphPanel;

   public MainFrame() {
      graphPanel = new JPanel();
      getContentPane().add(graphPanel, BorderLayout.CENTER);
      this.show(); // if the below lines are above this, they will both return 0
      System.out.println(graphPanel.getHeight());
      System.out.println(graphPanel.getWidth());
   }

   public static void main(String[] args) {
      MainFrame mf = new MainFrame();
   }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
grhs0043Author Commented:
thanks for the help.  Thar one line completely solved my problem(     this.show();   )

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.