Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java Language
Expertise: Beginner
Dec 8, 1997

Adjusting Java applications to screen resolution

Question:
We are developing a Java application which we want to distribute. We want our application main Frame/window to occupy the entire screen. But at runtime how do we adjust the size of our screen to the resolution at the clients machine. Is there a way in Java to rectify this problem??? Thanks Sameer

Answer:
To obtain the current screen size requires interfacing with the native window system. The Java AWT library allows this through the Toolkit class. The Toolkit class creates the bindings between the AWT classes and their native peers. You can obtain the default Toolkit by using the Toolkit.getDefaultToolkit() static method, or you can directly obtain the Toolkit used by a java.awt.Component derived class by calling its getToolkit() method. The Toolkit class has a method called getScreenSize() which returns a reference to a Dimension instance that contains the screen width and height. You can use this information to resize your frame to fill the entire screen or adjust its size to some percentage of the screen dimensions.

The following short example prints the screen width and height to standard output:

import java.awt.*;

public final class ScreenSize {
  public static final void main(String[] args) {
    Dimension size;
    size = Toolkit.getDefaultToolkit().getScreenSize();
    System.out.println("Width: " + size.width + " Height: " + size.height);
    System.exit(0);
  }
}
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date