Java Swing Tutorial - Java Swing Toolkit








We can use java.awt.Toolkit to communicate with the native toolkit system.

The Toolkit class provides a static getDefaultToolkit() factory method to get the toolkit object.

The Toolkit class contains useful methods to work with screen size and resolution, get access to the system clipboard, and to make a beeping sound, etc.

The following table lists a few of the methods of the Toolkit class.

IDMethod/Description
1abstract void beep()
Makes a beeping sound.
2static Toolkit getDefaultToolkit()
Returns the current Toolkit instance used in the application.
3int getScreenResolution()
Returns the screen resolution in terms of dots per inch.
4Dimension getScreenSize()
Returns a Dimension object that contains the width and the height of the screen in pixels.
5Clipboard getSystemClipboard()
Returns an instance of the Clipboard class that represents a system clipboard.




Screen Size

import java.awt.Dimension;
import java.awt.Toolkit;

public class Main {
  public static void main(String[] argv) throws Exception {
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    System.out.println(dim);
  }
}

The code above generates the following result.