Adjusting Java applications to screen resolution

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 tothe resolution at the clients machine. Is there a way in Java to rectifythis problem???ThanksSameer

To obtain the current screen size requires interfacing with the nativewindow system. The Java AWT library allows this through the Toolkitclass. The Toolkit class creates the bindings between the AWT classesand their native peers. You can obtain the default Toolkit by using theToolkit.getDefaultToolkit() static method, or you can directly obtainthe Toolkit used by a java.awt.Component derived class by calling itsgetToolkit() method.The Toolkit class has a method called getScreenSize() which returns areference to a Dimension instance that contains the screen width andheight. You can use this information to resize your frame to fill theentire screen or adjust its size to some percentage of the screendimensions.

The following short example prints the screen width and height tostandard 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);  }}
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: