Java Swing JToolBar Example

By | 2017-11-13T15:55:45+00:00 November 13th, 2017|java|0 Comments

In this tutorial I am going to show you how to create Toolbar using Java. Toolbars are used to display commonly used actions or controls.

Swing JToolBar provides component that allows to maintain commonly used actions like aliment, save, changing fonts and etc..

Swing JToolBar Example :

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

class MyFrameToolBarDemo extends JFrame {
    JToolBar toolbar;
    JButton New, Open, Save;
    JToggleButton Left, Center, Right;
    JComboBox fonts;
    ButtonGroup group;

    MyFrameToolBarDemo() {
        super("JToolbar Demo");


        toolbar = new JToolBar();

        New = new JButton(new ImageIcon(
        Open = new JButton(new ImageIcon(
        Save = new JButton(new ImageIcon(

        Left = new JToggleButton(new ImageIcon(
        Center = new JToggleButton(
                new ImageIcon(
        Right = new JToggleButton(new ImageIcon(

        group = new ButtonGroup();


        fonts = new JComboBox();
        fonts.addItem("Times New Roman");
        fonts.addItem("Comic Sans Ms");








        getContentPane().add(toolbar, BorderLayout.NORTH);

public class ToolBarDemo {
    public static void main(String args[]) throws Exception {
        new MyFrameToolBarDemo();

Output :

JToolBar Example

Font :

JToolBar Example 2

Happy Learning 🙂

About the Author:

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Leave A Comment