Java examples for 2D Graphics:Dimension
Dimension class represents the width and height of a component.
Dimension class is in the java.awt package.
import java.awt.Dimension; import javax.swing.JButton; public class Main { public static void main(String[] argv) throws Exception { // Create an object of the Dimension class with a width and height of 200 and 20 Dimension d = new Dimension(200, 20); JButton closeButton = new JButton("Close"); closeButton.setSize(200, 20);// w ww .j av a2 s . c o m closeButton.setSize(d); // Get the size of closeButton Dimension d2 = closeButton.getSize(); int width = d2.width; int height = d2.height; } }