java.awt.Toolkit - AWT Base Class

This section provides a tutorial example on how to use java.awt.Toolkit class to obtain the default Toolkit object, which also can provide information about the default graphics environment, the local screen.

java.awt.Toolkit is an AWT class acting as a base class for all implementations of AWT. This class also offers a static method, getDetaulToolkit(), to return a Toolkit object representing the default implementation of AWT.

You can use this default toolkit object to get information of the default graphics device, the local screen. For example, you can find out the size and resolution of the local screen.

To show you how to use the getDefaultToolkit() method, I wrote the following sample program:

 * Copyright (c) 2014,, All Rights Reserved.
import java.awt.*;
import javax.swing.*;
public class DefaultToolkit {
   public static void main(String[] a) {
      Toolkit t = Toolkit.getDefaultToolkit();
      Dimension d = t.getScreenSize();
      System.out.println("Screen size: "+d.width+", "+d.height);
      System.out.println("Screen resolution: "+t.getScreenResolution());


Screen size: 1024, 768
Screen resolution: 96

Comparing the output of with LocalGraphicsEnvironment, the toolkit screen size doesn't match the environment window bounds. I don't know why. I also don't know how to read the screen resolution value. Is it 96 DPI (Dots Per Inch)?

Sample programs listed in this section have been tested with JDK 1.3.1 to 1.8.0.

Last update: 2014.

Table of Contents

 About This Book

 Introduction of Java Swing Package

Graphics Environment of the Local System

 java.awt.GraphicsEnvironment - Graphics Environment Class

java.awt.Toolkit - AWT Base Class

 Testing Screen Resolution

 JFrame - Main Frame Class

 JLabel - Swing Label Class

 JButton - Swing Button Class

 JRadioButton - Swing Radio Button Class

 JTextField - Swing Text Field Class

 Menu Bar, Menus, Menu Items and Listeners

 Creating Internal Frames inside the Main Frame

 Layout of Components in a Container

 LookAndFeel and UIManager

 Option Dialog Boxes

 JEditorPane - The Editor Pane Class

 SwingWorker - The Background Task Worker


 PDF Printing Version