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:UndoDrawing.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Drawing Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    UndoableDrawingPanel drawingPanel = new UndoableDrawingPanel();

    UndoManager manager = new UndoManager();
    drawingPanel.addUndoableEditListener(manager);

    JToolBar toolbar = new JToolBar();
    toolbar.add(UndoManagerHelper.getUndoAction(manager));
    toolbar.add(UndoManagerHelper.getRedoAction(manager));

    Container content = frame.getContentPane();
    content.add(toolbar, BorderLayout.NORTH);
    content.add(drawingPanel, BorderLayout.CENTER);
    frame.setSize(300, 150);//from w  w  w  .j  av a  2 s  .  c  om
    frame.setVisible(true);
}

From source file:SwingToolBarSample.java

public static void main(String args[]) {

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println(actionEvent.getActionCommand());
        }//  w w  w. j  av  a  2 s. c  o  m
    };

    JFrame frame = new JFrame("JToolBar Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JToolBar toolbar = new JToolBar();
    toolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);

    for (int i = 0, n = buttonColors.length; i < n; i++) {
        Object color[] = buttonColors[i];
        if (color == null) {
            toolbar.addSeparator();
        } else {
            Icon icon = new DiamondIcon((Color) color[COLOR_POSITION], true, 20, 20);
            JButton button = new JButton(icon);
            button.setActionCommand((String) color[STRING_POSITION]);
            button.addActionListener(actionListener);
            toolbar.add(button);
        }
    }

    Action action = new ActionMenuSample.ShowAction(frame);
    toolbar.add(action);

    Container contentPane = frame.getContentPane();
    contentPane.add(toolbar, BorderLayout.NORTH);
    JTextArea textArea = new JTextArea();
    JScrollPane pane = new JScrollPane(textArea);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(350, 150);
    frame.setVisible(true);
}

From source file:UndoableDrawingPanel.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Drawing Sample2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    UndoableDrawingPanel drawingPanel = new UndoableDrawingPanel();

    UndoManager manager = new UndoManager();
    drawingPanel.addUndoableEditListener(manager);

    JToolBar toolbar = new JToolBar();
    JButton undoButton = new JButton(UndoManagerHelper.getUndoAction(manager));
    toolbar.add(undoButton);/*from   w  ww  . jav  a 2 s .co m*/
    JButton redoButton = new JButton(UndoManagerHelper.getRedoAction(manager));
    toolbar.add(redoButton);

    frame.add(toolbar, BorderLayout.NORTH);
    frame.add(drawingPanel, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);

}

From source file:UndoableDrawingPanel2.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Drawing Sample2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    UndoableDrawingPanel2 drawingPanel = new UndoableDrawingPanel2();

    UndoManager manager = new UndoManager();
    drawingPanel.addUndoableEditListener(manager);

    JToolBar toolbar = new JToolBar();
    toolbar.add(UndoManagerHelper.getUndoAction(manager));
    toolbar.add(UndoManagerHelper.getRedoAction(manager));

    Container content = frame.getContentPane();
    content.add(toolbar, BorderLayout.NORTH);
    content.add(drawingPanel, BorderLayout.CENTER);
    frame.setSize(300, 150);//from w w w.j a va 2 s .c  o m
    frame.setVisible(true);
}

From source file:UndoManagerHelper.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Undo Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextArea textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(textArea);

    UndoManager manager = new UndoManager();
    textArea.getDocument().addUndoableEditListener(manager);

    JToolBar toolbar = new JToolBar();
    JButton undoButton = new JButton(UndoManagerHelper.getUndoAction(manager));
    toolbar.add(undoButton);/*  w w  w.  j  a va2s  .  c  o  m*/
    JButton redoButton = new JButton(UndoManagerHelper.getRedoAction(manager));
    toolbar.add(redoButton);
    frame.add(toolbar, BorderLayout.NORTH);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:ListProperties.java

public static void main(String args[]) {
    final JFrame frame = new JFrame("List Properties");

    final CustomTableModel model = new CustomTableModel();
    model.uiDefaultsUpdate(UIManager.getDefaults());
    TableSorter sorter = new TableSorter(model);

    JTable table = new JTable(sorter);
    TableHeaderSorter.install(sorter, table);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            final String lafClassName = actionEvent.getActionCommand();
            Runnable runnable = new Runnable() {
                public void run() {
                    try {
                        UIManager.setLookAndFeel(lafClassName);
                        SwingUtilities.updateComponentTreeUI(frame);
                        // Added
                        model.uiDefaultsUpdate(UIManager.getDefaults());
                    } catch (Exception exception) {
                        JOptionPane.showMessageDialog(frame, "Can't change look and feel", "Invalid PLAF",
                                JOptionPane.ERROR_MESSAGE);
                    }/*from   w ww. java 2s.c o m*/
                }
            };
            SwingUtilities.invokeLater(runnable);
        }
    };

    JToolBar toolbar = new JToolBar();
    for (int i = 0, n = looks.length; i < n; i++) {
        JButton button = new JButton(looks[i].getName());
        button.setActionCommand(looks[i].getClassName());
        button.addActionListener(actionListener);
        toolbar.add(button);
    }

    Container content = frame.getContentPane();
    content.add(toolbar, BorderLayout.NORTH);
    JScrollPane scrollPane = new JScrollPane(table);
    content.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(400, 400);
    frame.setVisible(true);
}

From source file:Main.java

public static void showFrameWithToolBar(String toolBarPosition) {

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

    JToolBar tb = new JToolBar();

    gui.add(tb, toolBarPosition);//from  ww  w  .j  a v  a 2  s . c  om
    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);
}

From source file:Main.java

/**
 * Creates a {@link JToolBar} with the list items and {@link ActionMap}.
 *
 * @param actionMap//from   ww  w .j a  v a2 s.c  o m
 * @param items
 * @return
 */
public static JToolBar createToolbar(ActionMap actionMap, List<?> items) {
    final JToolBar toolBar = new JToolBar();
    populate(toolBar, actionMap, items);
    return toolBar;
}

From source file:Main.java

public Main() {
    JEditorPane editorPane = new JEditorPane();
    editorPane.setContentType("text/HTML");
    editorPane.setEditorKit(new HTMLEditorKit());
    editorPane.setText("<hr>Welcome to <b>java2s.com!</b><hr>");
    JToolBar bar = new JToolBar();
    bar.add(new StyledEditorKit.ForegroundAction("Red", Color.red));
    bar.add(new StyledEditorKit.ForegroundAction("Blue", Color.blue));
    bar.add(new StyledEditorKit.FontSizeAction("12", 12));
    bar.add(new StyledEditorKit.FontSizeAction("14", 14));
    bar.add(new StyledEditorKit.FontSizeAction("16", 16));
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setLocationRelativeTo(null);
    this.add(bar, BorderLayout.NORTH);
    this.add(editorPane, BorderLayout.CENTER);
    this.pack();//from  w w w.  ja v  a2s  . c  om
    this.setVisible(true);
}

From source file:MainClass.java

public MainClass() {
    super();//from w w w  .  ja v  a 2  s  .c om
    JToolBar urlToolBar = new JToolBar();
    mURLField = new JTextField(40);
    urlToolBar.add(new JLabel("Location:"));
    urlToolBar.add(mURLField);
    frame.add(urlToolBar, BorderLayout.NORTH);

    mEditorPane = new JEditorPane();
    mEditorPane.setEditable(false);
    frame.add(new JScrollPane(mEditorPane), BorderLayout.CENTER);

    openURL("http://www.java2s.com");

    mURLField.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            openURL(ae.getActionCommand());
        }
    });

    mEditorPane.addHyperlinkListener(new LinkActivator());

    setSize(500, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}