Download this source file


// LblDemo - Demo of some features of swing JLabels
// Written 2/2000 by Wayne Pollock, Tampa Florida USA.
// Adopted from code in "Java Swing" by Robert Eckstein, et. al.,
// 1998 O'Reilly & Assoc., pp. 84-85.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class LblDemo
{
   public static void main ( String [] args )
   {
      JLabel first = new JLabel( "First Name", JLabel.RIGHT );
        first.setFont( new Font( "Serif", Font.BOLD, 24 ) );
      JLabel middle = new JLabel( "Middle Name", JLabel.RIGHT );
        middle.setFont( new Font( "Serif", Font.BOLD, 24 ) );
      JLabel last = new JLabel( "Last Name", JLabel.RIGHT );
        last.setFont( new Font( "Serif", Font.BOLD, 24 ) );
      JTextField firstName = new JTextField( 10 );
        firstName.setFont( new Font( "Serif", Font.BOLD, 24 ) );
      JTextField middleName = new JTextField( 10 );
        middleName.setFont( new Font( "Serif", Font.BOLD, 24 ) );
      JTextField lastName = new JTextField( 10 );
        lastName.setFont( new Font( "Serif", Font.BOLD, 24 ) );

      middle.setBorder( new EtchedBorder() );
      lastName.setToolTipText( "Enter your last name" );

      first.setDisplayedMnemonic( 'F' );
      middle.setDisplayedMnemonic( 'M' );
      last.setDisplayedMnemonic( 'L' );
      first.setLabelFor( firstName );
      middle.setLabelFor( middleName );
      last.setLabelFor( lastName );

      JFrame frame = new JFrame();
      frame.addWindowListener( new WindowAdapter()
         {   public void windowClosing ( WindowEvent we )
             {   System.exit( 0 );
             }
         }
      );

      Container c = frame.getContentPane();
      c.setLayout( new GridLayout( 3, 2, 5, 5 ) );
      c.add( first );
      c.add( firstName );
      c.add( middle );
      c.add( middleName );
      c.add( last );
      c.add( lastName );
      frame.pack();
      frame.setVisible( true );
   }
}