Java Swing Tutorials

Java 2D API
previous Home next

We can make the Programming more interactive with Java 2D API. we can add figures, images, animation to our GUI and even pass visual information with the help of Java 2D API. We can easily use 2D within Swing components such as drop shadows since Swing is built on 2D package.

Pluggable Look and Feel

The Java Swing supports the look and feel features. Which means the dramatically changes in the component of the java swing like JFrame, JWindow etc. for visit it in several types of window we can create our own look and feel using Synth package. There are many types of the existing look and feels which are available to Swing programs provided by GTK+ look and feel. Moreover, the look and feel of the platform can be specified by the program while running and also to use Java look and feel can be specified by it.


package r4r;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class twoDAPItest extends JFrame{
JLabel msgLab;
public twoDAPItest(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
ActionListener actl = new ActionListener(){
public void actionPerformed(ActionEvent ae){
JButton btn;
JPanel btnPanel = new JPanel();
btnPanel.setBorder(new TitledBorder("Click at button"));
for (int i = 0; i < 3; i++){
btn = new JButton("Button " + (i + 1));
JPanel panel2 = new JPanel(new BorderLayout());
panel2.setBorder(new EmptyBorder(8, 8, 8, 8));
msgLab = new JLabel("No button pressed!");
panel2.add(msgLab, BorderLayout.NORTH);
panel2.add(btnPanel, BorderLayout.CENTER);
public static void main(String[] args){
new twoDAPItest();
previous Home next