Create JToolBar - Java Swing

Java examples for Swing:JToolBar

Introduction

A toolbar groups buttons in a JFrame.

JToolBar class represents a toolbar.

Create a horizontal JToolBar.

JToolBar toolBar = new JToolBar();

Create a horizontal JToolBar with a title. The title is displayed as a window title, when it floats as a separate window.

JToolBar toolBarWithTitle = new JToolBar("My ToolBar Title");

Create a Vertical toolbar

JToolBar vToolBar = new JToolBar(JToolBar.VERTICAL);

Add Buttons to toolbar

import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JToolBar;

public class Main {
  public static void main(String[] args) {
    JButton newButton = new JButton("New");
    newButton.setMargin(new Insets(0, 0, 0, 0));
    newButton.setToolTipText("Add a new policy");

    JToolBar toolBar = new JToolBar();
    toolBar.add(newButton);

  }
}

Related Tutorials