Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Get size of a JFrame

Posted on 2003-03-12
6
Medium Priority
?
235 Views
Last Modified: 2008-02-20
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...
0
Comment
Question by:grhs0043
  • 3
  • 3
6 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 8123767
make sure the frame is visible before you check getHeight and getWidth
0
 

Author Comment

by:grhs0043
ID: 8123940
It is .... i can see the frame when the program compiles but I cant get the height or width of it.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8123952
can you post your code?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:grhs0043
ID: 8124017
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
 
LVL 18

Accepted Solution

by:
bobbit31 earned 200 total points
ID: 8124074
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
 

Author Comment

by:grhs0043
ID: 8124102
thanks for the help.  Thar one line completely solved my problem(     this.show();   )

Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question