Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolBar;

public class Main {

    public static void showFrameWithToolBar(String toolBarPosition) {

        JPanel gui = new JPanel(new BorderLayout());

        JToolBar tb = new JToolBar();

        gui.add(tb, toolBarPosition);
        tb.add(new JButton("Button 1"));
        tb.add(new JButton("Button 2"));
        tb.addSeparator();
        tb.add(new JButton("Button 3"));
        tb.add(new JCheckBox("Check 1", true));

        JFrame f = new JFrame(toolBarPosition);
        f.setContentPane(gui);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLocationByPlatform(true);
        f.pack();

        f.setSize(400, 120);
        f.setVisible(true);
    }

    public static void main(String[] args) {

        showFrameWithToolBar(BorderLayout.PAGE_START);
        showFrameWithToolBar(BorderLayout.PAGE_END);
        showFrameWithToolBar(BorderLayout.LINE_START);
        showFrameWithToolBar(BorderLayout.LINE_END);
        showFrameWithToolBar(BorderLayout.CENTER);

    }
}