Example usage for javax.swing JToolBar JToolBar

List of usage examples for javax.swing JToolBar JToolBar

Introduction

In this page you can find the example usage for javax.swing JToolBar JToolBar.

Prototype

public JToolBar() 

Source Link

Document

Creates a new tool bar; orientation defaults to HORIZONTAL.

Usage

From source file:MainClass.java

MainClass(String title) {
    super(title);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JToolBar toolBar = new JToolBar();
    Action a = new AbstractAction("Demo") {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Action taken.");
        }//from w w  w  .  j  a v  a 2s  .c  om
    };

    JButton b = toolBar.add(a);
    b.setText("Demo Button");
    b.setToolTipText("Press me to take action.");

    JMenu mainMenu = new JMenu("Menu");
    JMenuItem mi = mainMenu.add(a);
    mi.getAccessibleContext().setAccessibleName("Menu item");

    JMenuBar mb = new JMenuBar();
    mb.add(mainMenu);
    setJMenuBar(mb);

    JPanel pane = new JPanel();
    pane.setLayout(new BorderLayout());
    pane.setPreferredSize(new Dimension(200, 100));
    pane.add(toolBar, BorderLayout.NORTH);
    setContentPane(pane);

    pack();
    setVisible(true);
}

From source file:ToolBarwithCheckBox.java

public ToolbarPanel() {
    setLayout(new BorderLayout());
    JToolBar toolbar = new JToolBar();
    for (int i = 1; i < 4; i++) {
        JCheckBox cbox = new JCheckBox("Checkbox #" + i);
        toolbar.add(cbox);/*www  .j av  a 2 s  .co  m*/
        cbox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JCheckBox source = (JCheckBox) (e.getSource());
                System.out.println("Toolbar " + source.getText());
            }
        });
    }

    add(toolbar, BorderLayout.NORTH);
}

From source file:MenuActionExample.java

public MenuActionExample() {
    super(true);//from   w  w  w .jav  a  2 s.c o m

    // Create a menu bar and give it a bevel border.
    menuBar = new JMenuBar();
    menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));

    // Create a menu and add it to the menu bar.
    JMenu menu = new JMenu("Menu");
    menuBar.add(menu);

    // Create a toolbar and give it an etched border.
    toolBar = new JToolBar();
    toolBar.setBorder(new EtchedBorder());

    // Instantiate a sample action with the NAME property of
    // "Download" and the appropriate SMALL_ICON property.
    SampleAction exampleAction = new SampleAction("Download", new ImageIcon("action.gif"));

    // Finally, add the sample action to the menu and the toolbar.
    // These methods are no longer preferred:
    // menu.add(exampleAction);
    // toolBar.add(exampleAction);
    // Instead, you should create actual menu items and buttons:
    JMenuItem exampleItem = new JMenuItem(exampleAction);
    JButton exampleButton = new JButton(exampleAction);
    menu.add(exampleItem);
    toolBar.add(exampleButton);
}

From source file:Main.java

public final JToolBar createToolBar() {

    toolbar = new JToolBar();

    shapeLabel = new JLabel("Shapes: ");
    addToToolbar(shapeLabel, 0, 1);//from  ww w  .j  a v  a 2 s.com

    shapeChooser = new JComboBox(shapeNames);
    shapeChooser.setSelectedIndex(0);
    addToToolbar(shapeChooser, 0, 2);
    colorLabel = new JLabel("Colors: ");

    addToToolbar(colorLabel, 0, 3);

    colorChooser = new JComboBox(colorNames);
    addToToolbar(colorChooser, 0, 4);

    return toolbar;
}

From source file:Main.java

public void build() {
    setSize(600, 600);/* ww w.j av a 2s  .co  m*/
    JTextPane textPane = new JTextPane();

    JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setPreferredSize(new Dimension(300, 300));

    JTextArea changeLog = new JTextArea(5, 30);
    changeLog.setEditable(false);
    JScrollPane scrollPaneForLog = new JScrollPane(changeLog);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog);
    splitPane.setOneTouchExpandable(true);

    JPanel statusPane = new JPanel(new GridLayout(1, 1));
    JLabel caretListenerLabel = new JLabel("Caret Status");
    statusPane.add(caretListenerLabel);

    JToolBar toolBar = new JToolBar();
    toolBar.add(new JButton("Btn1"));
    toolBar.add(new JButton("Btn2"));
    toolBar.add(new JButton("Btn3"));
    toolBar.add(new JButton("Btn4"));

    getContentPane().add(toolBar, BorderLayout.PAGE_START);
    getContentPane().add(splitPane, BorderLayout.CENTER);
    getContentPane().add(statusPane, BorderLayout.PAGE_END);

    JMenu editMenu = new JMenu("test");
    JMenu styleMenu = new JMenu("test");
    JMenuBar mb = new JMenuBar();
    mb.add(editMenu);
    mb.add(styleMenu);
    setJMenuBar(mb);

}

From source file:Main.java

Main() {
    gui.setBorder(new EmptyBorder(2, 3, 2, 3));

    String userDirLocation = System.getProperty("user.dir");
    File userDir = new File(userDirLocation);
    // default to user directory
    fileChooser = new JFileChooser(userDir);

    Action open = new AbstractAction("Open") {
        @Override//  ww w. java2 s. c  om
        public void actionPerformed(ActionEvent e) {
            int result = fileChooser.showOpenDialog(gui);
            if (result == JFileChooser.APPROVE_OPTION) {
                try {
                    File f = fileChooser.getSelectedFile();
                    FileReader fr = new FileReader(f);
                    output.read(fr, f);
                    fr.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    };

    Action save = new AbstractAction("Save") {
        @Override
        public void actionPerformed(ActionEvent e) {
            int result = fileChooser.showSaveDialog(gui);
            System.out.println("Not supported yet.");
        }
    };

    JToolBar tb = new JToolBar();
    gui.add(tb, BorderLayout.PAGE_START);
    tb.add(open);
    tb.add(save);

    gui.add(new JScrollPane(output));
}

From source file:com.intuit.tank.proxy.settings.ui.ProxyConfigDialog.java

private JToolBar getToolbar() {
    if (toolbar == null) {
        toolbar = new JToolBar();
        JButton saveButton = new JButton("Save",
                new ImageIcon(ProxyConfigDialog.class.getResource("/icons/16/save_as.png")));
        saveButton.addActionListener(new ActionListener() {
            @Override/*from w  w  w  . j a v a  2 s. co  m*/
            public void actionPerformed(ActionEvent e) {
                try {
                    saveConfig(false);
                } catch (IOException e1) {
                    throw new IllegalArgumentException(e1);
                }
            }
        });
        JButton saveasButton = new JButton("Save As...",
                new ImageIcon(ProxyConfigDialog.class.getResource("/icons/16/save_as.png")));
        saveasButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    saveConfig(true);
                } catch (IOException e1) {
                    throw new IllegalArgumentException(e1);
                }
            }
        });
        JButton openButton = new JButton("Open",
                new ImageIcon(ProxyConfigDialog.class.getResource("/icons/16/open_folder.png")));
        openButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                openConfig();
            }
        });
        toolbar.add(Box.createHorizontalStrut(5));
        toolbar.add(openButton);
        toolbar.add(Box.createHorizontalStrut(5));
        toolbar.add(saveButton);
        toolbar.add(Box.createHorizontalStrut(5));
        toolbar.add(saveasButton);
    }

    return toolbar;
}

From source file:ToolBarTest.java

public ToolBarFrame() {
    setTitle("ToolBarTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // add a panel for color change

    panel = new JPanel();
    add(panel, BorderLayout.CENTER);

    // set up actions

    Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.BLUE);
    Action yellowAction = new ColorAction("Yellow", new ImageIcon("yellow-ball.gif"), Color.YELLOW);
    Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.RED);

    Action exitAction = new AbstractAction("Exit", new ImageIcon("exit.gif")) {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);/*from   w w w  .  ja  va2s.  co m*/
        }
    };
    exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit");

    // populate tool bar

    JToolBar bar = new JToolBar();
    bar.add(blueAction);
    bar.add(yellowAction);
    bar.add(redAction);
    bar.addSeparator();
    bar.add(exitAction);
    add(bar, BorderLayout.NORTH);

    // populate menu

    JMenu menu = new JMenu("Color");
    menu.add(yellowAction);
    menu.add(blueAction);
    menu.add(redAction);
    menu.add(exitAction);
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(menu);
    setJMenuBar(menuBar);
}

From source file:SiteFrame.java

public SiteManager() {
    super("Web Site Manager");
    setSize(450, 250);/*from w w w .j a v a2s  .c  o  m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    Container contentPane = getContentPane();

    JToolBar jtb = new JToolBar();
    jtb.add(new CutAction(this));
    jtb.add(new CopyAction(this));
    jtb.add(new PasteAction(this));
    contentPane.add(jtb, BorderLayout.NORTH);

    // Add our LayeredPane object for the internal frames.
    desktop = new JDesktopPane();
    contentPane.add(desktop, BorderLayout.CENTER);
    addSiteFrame("Sample");
}