How to get current Resolution of Window in JAVA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amitpathak
    New Member
    • Jan 2007
    • 20

    #1

    How to get current Resolution of Window in JAVA

    Hi

    I want to know how to get current size or resolution of window or frame.I mean
    I made a program in which i Created a frame for 800*600 window but what changes i required to run the same program in 1024*728 or any other resolution
    to obtain the full frame or window
  • Cheez It
    New Member
    • Dec 2006
    • 4

    #2
    All the GUI classes extend Component, so you can use the getWidth() and getHeight() methods to find the current dimensions of a frame or window.

    Comment

    • rengaraj
      New Member
      • Jan 2007
      • 168

      #3
      Originally posted by Cheez It
      All the GUI classes extend Component, so you can use the getWidth() and getHeight() methods to find the current dimensions of a frame or window.
      Java 1.4 or newer
      If you are using Java 1.4 or newer, you can use the simple method setLocationRela tiveTo(null) on the dialog box, frame, or window to center it.

      Java 1.3 or older
      //Create a new JFrame
      JFrame frame = new JFrame("Demo");
      frame.setSize(4 00, 600);

      //Calculate the frame location
      int x = (screenSize.wid th - frame.getWidth( )) / 2;
      int y = (screenSize.hei ght - frame.getHeight ()) / 2;

      //Set the new frame location
      frame.setLocati on(x, y);

      Comment

      Working...