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(String name) 

Source Link

Document

Creates a new tool bar with the specified name.

Usage

From source file:Main.java

public static void main(String[] args) {
    JToolBar toolbar = new JToolBar(JToolBar.VERTICAL);

    JButton selectb = new JButton(new ImageIcon("select.gif"));
    JButton freehandb = new JButton(new ImageIcon("freehand.gif"));
    JButton shapeedb = new JButton(new ImageIcon("shapeed.gif"));
    JButton penb = new JButton(new ImageIcon("pen.gif"));

    toolbar.add(selectb);/* www .  j ava2s  . c  om*/
    toolbar.add(freehandb);
    toolbar.add(shapeedb);
    toolbar.add(penb);

    JFrame f = new JFrame();
    f.add(toolbar, BorderLayout.WEST);

    f.setSize(250, 350);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JToolBar toolBar = new JToolBar("Still draggable");

    toolBar.setFloatable(false);/*from   w w w  . ja v  a2  s.co  m*/
    toolBar.setRollover(true);

    toolBar.add(new JButton("New"));
    toolBar.addSeparator();
    toolBar.add(new JButton("Open"));

    frame.add(toolBar, "North");

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ToolBarExample.java

public ToolBarExample() {
    menuBar = new JMenuBar();

    // Create a set of actions to use in both the menu and toolbar
    DemoAction leftJustifyAction = new DemoAction("Left", new ImageIcon("1.gif"), "Left justify text", 'L');
    DemoAction rightJustifyAction = new DemoAction("Right", new ImageIcon("2.gif"), "Right justify text", 'R');
    DemoAction centerJustifyAction = new DemoAction("Center", new ImageIcon("3.gif"), "Center justify text",
            'M');
    DemoAction fullJustifyAction = new DemoAction("Full", new ImageIcon("4.gif"), "Full justify text", 'F');

    JMenu formatMenu = new JMenu("Justify");
    formatMenu.add(leftJustifyAction);/*from  w  w  w  .j  a  v a2  s. com*/
    formatMenu.add(rightJustifyAction);
    formatMenu.add(centerJustifyAction);
    formatMenu.add(fullJustifyAction);

    menuBar.add(formatMenu);

    toolBar = new JToolBar("Formatting");
    toolBar.add(leftJustifyAction);
    toolBar.add(rightJustifyAction);
    toolBar.add(centerJustifyAction);
    toolBar.add(fullJustifyAction);

    toolBar.addSeparator();
    JLabel label = new JLabel("Font");
    toolBar.add(label);

    toolBar.addSeparator();
    JComboBox combo = new JComboBox(fonts);
    combo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                pane.getStyledDocument().insertString(0,
                        "Font [" + ((JComboBox) e.getSource()).getSelectedItem() + "] chosen!\n", null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    toolBar.add(combo);

    //  Disable one of the Actions
    fullJustifyAction.setEnabled(false);
}

From source file:components.ToolBarDemo.java

public ToolBarDemo() {
    super(new BorderLayout());

    //Create the toolbar.
    JToolBar toolBar = new JToolBar("Still draggable");
    addButtons(toolBar);//from  w  w  w. j  a v  a  2  s .c  o m

    //Create the text area used for output.  Request
    //enough space for 5 rows and 30 columns.
    textArea = new JTextArea(5, 30);
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);

    //Lay out the main panel.
    setPreferredSize(new Dimension(450, 130));
    add(toolBar, BorderLayout.PAGE_START);
    add(scrollPane, BorderLayout.CENTER);
}

From source file:components.ToolBarDemo2.java

public ToolBarDemo2() {
    super(new BorderLayout());

    //Create the toolbar.
    JToolBar toolBar = new JToolBar("Still draggable");
    addButtons(toolBar);//from  ww  w.  j a  v a 2  s  . com
    toolBar.setFloatable(false);
    toolBar.setRollover(true);

    //Create the text area used for output.  Request
    //enough space for 5 rows and 30 columns.
    textArea = new JTextArea(5, 30);
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);

    //Lay out the main panel.
    setPreferredSize(new Dimension(450, 130));
    add(toolBar, BorderLayout.PAGE_START);
    add(scrollPane, BorderLayout.CENTER);
}

From source file:com.lfv.lanzius.server.WorkspacePanel.java

private void initComponents() {

    view = new WorkspaceView(server, this);

    toolBar = new JToolBar(Config.TITLE + " - Toolbar");

    buttonServer = new JButton();
    buttonLink = new JButton();
    buttonLoad = new JButton();
    buttonUnlink = new JButton();
    buttonSwap = new JButton();
    buttonMonitor = new JButton();
    buttonStart = new JButton();
    buttonStop = new JButton();
    buttonIsaStart = new JButton();
    //buttonIsaToggle = new JButton();

    setLayout(new BorderLayout());

    iconServerOn = new ImageIcon("data/resources/icons/Server_on.png");
    iconServerOff = new ImageIcon("data/resources/icons/Server_off.png");

    buttonServer.setFont(new Font("Dialog", 0, 10));
    buttonServer.setIcon(iconServerOff);
    buttonServer.setText("Server");
    buttonServer.setDisabledIcon(iconServerOff);
    buttonServer.setEnabled(false);/*  w ww .  ja  v a2s. co  m*/
    buttonServer.setFocusPainted(false);
    buttonServer.setHorizontalTextPosition(SwingConstants.CENTER);
    buttonServer.setIconTextGap(0);
    buttonServer.setVerticalTextPosition(SwingConstants.BOTTOM);

    toolBar.add(buttonServer);

    toolBar.addSeparator(new Dimension(40, 1));

    buttonLoad.setFont(new Font("Dialog", 0, 10));
    buttonLoad.setIcon(new ImageIcon("data/resources/icons/Load.png"));
    buttonLoad.setText("Load");
    buttonLoad.setToolTipText("Load an exercise xml file");
    buttonLoad.setDisabledIcon(new ImageIcon("data/resources/icons/Load_gray.png"));
    buttonLoad.setEnabled(false);
    buttonLoad.setFocusPainted(false);
    buttonLoad.setHorizontalTextPosition(SwingConstants.CENTER);
    buttonLoad.setIconTextGap(0);
    buttonLoad.setVerticalTextPosition(SwingConstants.BOTTOM);
    buttonLoad.addActionListener(this);
    toolBar.add(buttonLoad);

    toolBar.addSeparator();
    buttonLink.setFont(new Font("Dialog", 0, 10));
    buttonLink.setIcon(new ImageIcon("data/resources/icons/Link.png"));
    buttonLink.setText("Link");
    buttonLink.setToolTipText("Link one or more players to the selected terminal");
    buttonLink.setDisabledIcon(new ImageIcon("data/resources/icons/Link_gray.png"));
    buttonLink.setEnabled(false);
    buttonLink.setFocusPainted(false);
    buttonLink.setHorizontalTextPosition(SwingConstants.CENTER);
    buttonLink.setIconTextGap(0);
    buttonLink.setVerticalTextPosition(SwingConstants.BOTTOM);
    buttonLink.addActionListener(this);
    toolBar.add(buttonLink);

    buttonUnlink.setFont(new Font("Dialog", 0, 10));
    buttonUnlink.setIcon(new ImageIcon("data/resources/icons/Unlink.png"));
    buttonUnlink.setText("Unlink");
    buttonUnlink.setToolTipText("Unlink players from selected terminal(s) or group(s)");
    buttonUnlink.setDisabledIcon(new ImageIcon("data/resources/icons/Unlink_gray.png"));
    buttonUnlink.setEnabled(false);
    buttonUnlink.setFocusPainted(false);
    buttonUnlink.setHorizontalTextPosition(SwingConstants.CENTER);
    buttonUnlink.setIconTextGap(0);
    buttonUnlink.setVerticalTextPosition(SwingConstants.BOTTOM);
    buttonUnlink.addActionListener(this);
    toolBar.add(buttonUnlink);

    buttonSwap.setFont(new Font("Dialog", 0, 10));
    buttonSwap.setIcon(new ImageIcon("data/resources/icons/Swap.png"));
    buttonSwap.setText("Swap");
    buttonSwap.setToolTipText("Swap the players linked to the two selected terminals");
    buttonSwap.setDisabledIcon(new ImageIcon("data/resources/icons/Swap_gray.png"));
    buttonSwap.setEnabled(false);
    buttonSwap.setFocusPainted(false);
    buttonSwap.setHorizontalTextPosition(SwingConstants.CENTER);
    buttonSwap.setIconTextGap(0);
    buttonSwap.setVerticalTextPosition(SwingConstants.BOTTOM);
    buttonSwap.addActionListener(this);
    toolBar.add(buttonSwap);

    toolBar.addSeparator();

    buttonMonitor.setFont(new Font("Dialog", 0, 10));
    buttonMonitor.setIcon(new ImageIcon("data/resources/icons/Listen.png"));
    buttonMonitor.setText("Monitor");
    buttonMonitor.setToolTipText("Listen and record the selected terminal");
    buttonMonitor.setDisabledIcon(new ImageIcon("data/resources/icons/Listen_gray.png"));
    buttonMonitor.setEnabled(false);
    buttonMonitor.setFocusPainted(false);
    buttonMonitor.setHorizontalTextPosition(SwingConstants.CENTER);
    buttonMonitor.setIconTextGap(0);
    buttonMonitor.setVerticalTextPosition(SwingConstants.BOTTOM);
    buttonMonitor.addActionListener(this);
    toolBar.add(buttonMonitor);

    toolBar.addSeparator();

    buttonStart.setFont(new Font("Dialog", 0, 10));
    buttonStart.setIcon(new ImageIcon("data/resources/icons/Start.png"));
    buttonStart.setText("Start");
    buttonStart.setToolTipText("Start the selected group(s)");
    buttonStart.setDisabledIcon(new ImageIcon("data/resources/icons/Start_gray.png"));
    buttonStart.setEnabled(false);
    buttonStart.setFocusPainted(false);
    buttonStart.setHorizontalTextPosition(SwingConstants.CENTER);
    buttonStart.setIconTextGap(0);
    buttonStart.setVerticalTextPosition(SwingConstants.BOTTOM);
    buttonStart.addActionListener(this);
    toolBar.add(buttonStart);

    buttonStop.setFont(new Font("Dialog", 0, 10));
    buttonStop.setIcon(new ImageIcon("data/resources/icons/Stop.png"));
    buttonStop.setText("Stop");
    buttonStop.setToolTipText("Stop the selected group(s)");
    buttonStop.setDisabledIcon(new ImageIcon("data/resources/icons/Stop_gray.png"));
    buttonStop.setEnabled(false);
    buttonStop.setFocusPainted(false);
    buttonStop.setHorizontalTextPosition(SwingConstants.CENTER);
    buttonStop.setIconTextGap(0);
    buttonStop.setVerticalTextPosition(SwingConstants.BOTTOM);
    buttonStop.addActionListener(this);
    toolBar.add(buttonStop);

    toolBar.addSeparator();

    buttonIsaStart.setFont(new Font("Dialog", 0, 10));
    buttonIsaStart.setIcon(new ImageIcon("data/resources/icons/StartISA.png"));
    buttonIsaStart.setText("ISA Start/Stop");
    buttonIsaStart.setToolTipText("Start measure work load for selected clients");
    buttonIsaStart.setDisabledIcon(new ImageIcon("data/resources/icons/StartISA_gray.png"));
    buttonIsaStart.setEnabled(true);
    buttonIsaStart.setFocusPainted(false);
    buttonIsaStart.setHorizontalTextPosition(SwingConstants.CENTER);
    buttonIsaStart.setIconTextGap(0);
    buttonIsaStart.setVerticalTextPosition(SwingConstants.BOTTOM);
    buttonIsaStart.addActionListener(this);
    toolBar.add(buttonIsaStart);

    /*
    buttonIsaToggle.setFont(new Font("Dialog", 0, 10));
    buttonIsaToggle.setIcon(new ImageIcon("data/resources/icons/StopISA.png"));
    buttonIsaToggle.setText("Toggle ISA");
    buttonIsaToggle.setToolTipText("Start/Stop measure work load for selected clients");
    buttonIsaToggle.setDisabledIcon(new ImageIcon("data/resources/icons/StopISA_gray.png"));
    buttonIsaToggle.setEnabled(false);
    buttonIsaToggle.setFocusPainted(false);
    buttonIsaToggle.setHorizontalTextPosition(SwingConstants.CENTER);
    buttonIsaToggle.setIconTextGap(0);
    buttonIsaToggle.setVerticalTextPosition(SwingConstants.BOTTOM);
    buttonIsaToggle.addActionListener(this);
    toolBar.add(buttonIsaToggle);
    */

    add(toolBar, BorderLayout.NORTH);
    add(view, BorderLayout.CENTER);
}

From source file:SwingToolBarDemo.java

public SwingToolBarDemo() {
    super(new BorderLayout());

    //Create the toolbar.
    JToolBar toolBar = new JToolBar("Still draggable");
    addButtons(toolBar);/* w ww  .j  av a 2 s  . co  m*/

    //Create the text area used for output. Request
    //enough space for 5 rows and 30 columns.
    textArea = new JTextArea(5, 30);
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);

    //Lay out the main panel.
    setPreferredSize(new Dimension(450, 130));
    add(toolBar, BorderLayout.PAGE_START);
    add(scrollPane, BorderLayout.CENTER);
}

From source file:ToolBarDemo2.java

public ToolBarDemo2() {
    super(new BorderLayout());

    //Create the toolbar.
    JToolBar toolBar = new JToolBar("Still draggable");
    addButtons(toolBar);/*  www  .  j  a v  a 2 s  .  c o m*/
    toolBar.setFloatable(false);
    toolBar.setRollover(true);

    //Create the text area used for output. Request
    //enough space for 5 rows and 30 columns.
    textArea = new JTextArea(5, 30);
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);

    //Lay out the main panel.
    setPreferredSize(new Dimension(450, 130));
    add(toolBar, BorderLayout.PAGE_START);
    add(scrollPane, BorderLayout.CENTER);
}

From source file:io.github.tavernaextras.biocatalogue.ui.filtertree.FilterTreePane.java

/**
 * @return A toolbar that replicates all actions available in the contextual menu of
 *         the filtering tree - mainly: saving current filter, reloading filter tree,
 *         expanding/collapsing and selecting/deselecting everything in the tree.
 *//*from  w  w w .j a  va2 s . c  o  m*/
private JToolBar createTreeActionToolbar() {

    // the actual toolbar - no actions are added to it yet: done in a separate method
    JToolBar tbTreeActions = new JToolBar(JToolBar.HORIZONTAL);
    tbTreeActions.setAlignmentX(RIGHT_ALIGNMENT);
    tbTreeActions.setBorderPainted(true);
    tbTreeActions.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    tbTreeActions.setFloatable(false);
    return (tbTreeActions);
}

From source file:net.schweerelos.parrot.CombinedParrotApp.java

private void initGUI(Properties properties) {
    try {//from w  w w.  j  a  v a2s . c o m
        this.setTitle(APP_TITLE);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                for (MainViewComponent mainViewComponent : mainViews) {
                    if (mainViewComponent instanceof ParrotStateListener) {
                        ((ParrotStateListener) mainViewComponent).parrotExiting();
                    }
                }
            }
        });
        setSize(920, 690);

        getContentPane().setLayout(new BorderLayout());

        UserInterfaceManager uiManager = new UserInterfaceManager(properties);
        navigators = new ArrayList<NavigatorComponent>(4);

        // main view
        listView = uiManager.createMainViewComponent(Style.TABLE);
        graphView = uiManager.createMainViewComponent(Style.GRAPH);
        mainViews.add(listView);
        mainViews.add(graphView);

        final JTabbedPane mainPanel = new JTabbedPane();
        mainPanel.add(graphView.getTitle(), graphView.asJComponent());
        mainPanel.add(listView.getTitle(), listView.asJComponent());

        mainPanel.setSelectedIndex(0);
        activeMainView = graphView;
        mainPanel.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                if (e.getSource() != mainPanel) {
                    return;
                }
                int selectedIndex = mainPanel.getSelectedIndex();
                if (selectedIndex == 0) {
                    activeMainView = graphView;
                } else if (selectedIndex == 1) {
                    activeMainView = listView;
                } else {
                    Logger logger = Logger.getLogger(CombinedParrotApp.class);
                    logger.warn("unknown tab index selected: " + selectedIndex);
                }
            }
        });

        add(mainPanel, BorderLayout.CENTER);

        // navigators
        JToolBar navigatorsBar = new JToolBar(JToolBar.HORIZONTAL);
        navigatorsBar.setMargin(new Insets(0, 11, 0, 0));
        navigatorsBar.setFloatable(false);
        getContentPane().add(navigatorsBar, BorderLayout.PAGE_START);

        // timeline
        NavigatorComponent timelineNavigator = uiManager.createTimelineNavigationComponent();
        navigators.add(timelineNavigator);

        JFrame timelineFrame = new JFrame(timelineNavigator.getNavigatorName() + "  " + APP_TITLE);

        timelineFrame.getContentPane().add(timelineNavigator.asJComponent());
        timelineFrame.pack();
        Point preferredLocation = new Point(0, 0);
        preferredFrameLocations.put(timelineFrame, preferredLocation);

        if (timelineNavigator.hasShowHideListener()) {
            timelineFrame.addComponentListener(timelineNavigator.getShowHideListener());
        }
        timelineFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

        JToggleButton timelineButton = setupNavigatorButton(timelineNavigator.getNavigatorName(),
                timelineNavigator.getAcceleratorKey(), timelineNavigator);
        navigatorsBar.add(timelineButton);

        // map      
        NavigatorComponent mapNavigator = uiManager.createMapNavigationComponent();
        navigators.add(mapNavigator);

        JFrame mapFrame = new JFrame(mapNavigator.getNavigatorName() + "  " + APP_TITLE);

        mapFrame.getContentPane().add(mapNavigator.asJComponent());
        mapFrame.pack();
        preferredLocation = new Point(0,
                Toolkit.getDefaultToolkit().getScreenSize().height - mapFrame.getHeight());
        preferredFrameLocations.put(mapFrame, preferredLocation);

        if (mapNavigator.hasShowHideListener()) {
            mapFrame.addComponentListener(mapNavigator.getShowHideListener());
        }
        mapFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

        JToggleButton mapButton = setupNavigatorButton(mapNavigator.getNavigatorName(),
                mapNavigator.getAcceleratorKey(), mapNavigator);
        navigatorsBar.add(mapButton);

        // search      
        NavigatorComponent searchNavigator = uiManager.createSearchComponent();
        navigators.add(searchNavigator);

        JFrame searchFrame = new JFrame(searchNavigator.getNavigatorName() + "  " + APP_TITLE);

        searchFrame.getContentPane().add(searchNavigator.asJComponent());
        searchFrame.pack();
        preferredLocation = new Point(
                Toolkit.getDefaultToolkit().getScreenSize().width - searchFrame.getWidth(), 0);
        preferredFrameLocations.put(searchFrame, preferredLocation);

        if (searchNavigator.hasShowHideListener()) {
            searchFrame.addComponentListener(searchNavigator.getShowHideListener());
        }
        searchFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

        JToggleButton searchButton = setupNavigatorButton(searchNavigator.getNavigatorName(),
                searchNavigator.getAcceleratorKey(), searchNavigator);
        navigatorsBar.add(searchButton);

        // connections
        NavigatorComponent chainNavigator = uiManager.createChainNavigationComponent();
        navigators.add(chainNavigator);

        if (chainNavigator instanceof PickListener) {
            for (MainViewComponent mainViewComponent : mainViews) {
                mainViewComponent.addPickListener((PickListener) chainNavigator);
            }
        }

        if (chainNavigator.hasShowHideListener()) {
            chainNavigator.asJComponent().addComponentListener(chainNavigator.getShowHideListener());
        }

        JToggleButton connectionsButton = setupNavigatorButton(chainNavigator.getNavigatorName(),
                chainNavigator.getAcceleratorKey(), chainNavigator);
        navigatorsBar.add(connectionsButton);

        add(chainNavigator.asJComponent(), BorderLayout.PAGE_END);
        chainNavigator.asJComponent().setVisible(false);
    } catch (RuntimeException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    } catch (UnknownStyleException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
}