A simple frame containing a toolbar made up of several Buttons : Toolbar « Swing JFC « Java






A simple frame containing a toolbar made up of several Buttons

A simple frame containing a toolbar made up of several Buttons
    

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class ToolbarFrame1 extends Frame {

  Button cutButton, copyButton, pasteButton;

  public ToolbarFrame1() {
    super("Toolbar Example (AWT)");
    setSize(450, 250);
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });

    ActionListener printListener = new ActionListener() {
      public void actionPerformed(ActionEvent ae) {
        System.out.println(ae.getActionCommand());
      }
    };

    Panel toolbar = new Panel();
    toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));

    cutButton = new Button("Cut");
    cutButton.addActionListener(printListener);
    toolbar.add(cutButton);

    copyButton = new Button("Copy");
    copyButton.addActionListener(printListener);
    toolbar.add(copyButton);

    pasteButton = new Button("Paste");
    pasteButton.addActionListener(printListener);
    toolbar.add(pasteButton);

    add(toolbar, BorderLayout.NORTH);
  }

  public static void main(String args[]) {
    ToolbarFrame1 tf1 = new ToolbarFrame1();
    tf1.setVisible(true);
  }
}
           
         
    
    
    
  








Related examples in the same category

1.Create two toolbars
2.Shows a vertical toolbar.
3.An example of JToolBarAn example of JToolBar
4.Toolbar SampleToolbar Sample
5.JToolBar DemoJToolBar Demo
6.Swing ToolBar DemoSwing ToolBar Demo
7.ToolBar Demo 2ToolBar Demo 2
8.Toolbar and menubarToolbar and menubar
9.Simple toolbarSimple toolbar
10.Working with a ToolbarWorking with a Toolbar
11.Get ToolBar PropertiesGet ToolBar Properties
12.If the toolbar is to be floatable, it must be added to a container with a BorderLayout.
13.Highlighting Buttons in a JToolbar Container While Under the Cursor
14.JToolbar: Toolbars provide a quick access to the most frequently used commands.JToolbar: Toolbars provide a quick access to the most frequently used commands.
15.Preventing a JToolbar Container from Floating
16.Determining When a Floatable JToolBar Container Changes Orientation
17.Create a vertical toolbar
18.Add various buttons to the toolbar
19.ToolBar UI SampleToolBar UI Sample
20.ToolBar button
21.This class represents a separator for the toolbar buttons.
22.Buttons used in toolbars.
23.A frame with a toolbar and menu for color changesA frame with a toolbar and menu for color changes