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

public static void main(String[] argv) throws Exception {
    JToolBar toolbar = new JToolBar();
    toolbar.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            String propName = evt.getPropertyName();
            if ("orientation".equals(propName)) {
                Integer oldValue = (Integer) evt.getOldValue();
                Integer newValue = (Integer) evt.getNewValue();
                if (newValue.intValue() == JToolBar.HORIZONTAL) {
                    System.out.println("horizontal orientation");
                } else {
                    System.out.println("vertical orientation");
                }/*from w ww.  j  av  a2 s  . co m*/
            }
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Create a horizontal toolbar
    JToolBar toolbar = new JToolBar();

    // Get current rollover mode
    boolean b = toolbar.isRollover();

    // Enable rollover mode
    toolbar.setRollover(true);//  w ww. ja va 2s.co m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    // Create a horizontal toolbar
    JToolBar toolbar = new JToolBar();

    // Get current floatability
    boolean b = toolbar.isFloatable();

    // Disable floatability
    toolbar.setFloatable(false);//from w ww.j a  v a2  s  .  c o m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Add the toolbar to a frame
    JFrame frame = new JFrame();
    JToolBar toolbar = new JToolBar();

    frame.getContentPane().add(toolbar, BorderLayout.NORTH);
    frame.pack();//from w  ww  .java  2  s  .co  m
    frame.setVisible(true);
}

From source file:ToolBarTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    JToolBar bar;/*from www  .j a  va 2  s  .  com*/
    bar = new JToolBar();
    JToggleButton jb;
    for (int i = 0; i < 8; i++) {
        jb = new JToggleButton("" + i);
        bar.add(jb);
        if (i == 5) {
            bar.addSeparator();
        }
    }
    contentPane.add(bar, BorderLayout.NORTH);
    frame.setSize(300, 300);
    frame.show();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JToolBar toolbar = new JToolBar();
    ImageIcon icon = new ImageIcon("icon.gif");
    Action action = new AbstractAction("Button Label", icon) {
        public void actionPerformed(ActionEvent evt) {
        }// w  w  w .  j  a v  a 2s.c  om
    };

    JButton c1 = new JButton(action);
    c1.setText(null);
    c1.setMargin(new Insets(0, 0, 0, 0));
    toolbar.add(c1);

    JToggleButton c2 = new JToggleButton(action);
    c2.setText(null);
    c2.setMargin(new Insets(0, 0, 0, 0));
    toolbar.add(c2);

    JComboBox c3 = new JComboBox(new String[] { "A", "B", "C" });
    c3.setPrototypeDisplayValue("XXXXXXXX"); // Set a desired width
    c3.setMaximumSize(c3.getMinimumSize());
    toolbar.add(c3);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame f = new JFrame("JToolBar Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JToolBar toolbar = new JToolBar();
    Icon icon = MetalIconFactory.getFileChooserDetailViewIcon();
    JToggleButton button = new JToggleButton(icon);
    toolbar.add(button);//from  w  w w.  j ava  2 s. co  m
    icon = MetalIconFactory.getFileChooserHomeFolderIcon();
    button = new JToggleButton(icon);
    toolbar.add(button);
    icon = MetalIconFactory.getFileChooserListViewIcon();
    button = new JToggleButton(icon);
    toolbar.add(button);
    f.add(toolbar, BorderLayout.NORTH);
    f.setSize(300, 100);
    f.setVisible(true);
}

From source file:Toolbars.java

public static void main(String[] args) {
    JToolBar toolbar1 = new JToolBar();
    JToolBar toolbar2 = new JToolBar();

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    JButton newb = new JButton(new ImageIcon("new.png"));
    JButton openb = new JButton(new ImageIcon("open.png"));
    JButton saveb = new JButton(new ImageIcon("save.png"));

    toolbar1.add(newb);// w  w  w.  j a v a 2  s .  c  o m
    toolbar1.add(openb);
    toolbar1.add(saveb);
    toolbar1.setAlignmentX(0);

    JButton exitb = new JButton(new ImageIcon("exit.png"));
    toolbar2.add(exitb);
    toolbar2.setAlignmentX(0);

    exitb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    panel.add(toolbar1);
    panel.add(toolbar2);

    JFrame f = new JFrame();
    f.add(panel, BorderLayout.NORTH);

    f.setSize(300, 200);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JToolbar Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    JToolBar toolbar = new JToolBar();
    Icon icon = MetalIconFactory.getFileChooserDetailViewIcon();
    JToggleButton button = new JToggleButton(icon);
    toolbar.add(button);//from ww  w.  j av a2 s .  c o m
    icon = MetalIconFactory.getFileChooserHomeFolderIcon();
    button = new JToggleButton(icon);
    toolbar.add(button);
    icon = MetalIconFactory.getFileChooserListViewIcon();
    button = new JToggleButton(icon);
    toolbar.add(button);
    content.add(toolbar, BorderLayout.NORTH);
    f.setSize(300, 100);
    f.setVisible(true);
}

From source file:ToolBarSample.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("JToolBar Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JToolBar toolbar = new JToolBar();
    toolbar.setRollover(true);/*from www. ja v  a2s .  com*/

    JButton button = new JButton("button");
    toolbar.add(button);
    toolbar.addSeparator();

    toolbar.add(new JButton("button 2"));

    toolbar.add(new JComboBox(new String[] { "A", "B", "C" }));

    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);
}