JToolBar: add(JComponent com) : JToolBar « javax.swing « Java by API






JToolBar: add(JComponent com)

 
import java.awt.BorderLayout;

import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.plaf.metal.MetalIconFactory;

public class MainClass {
  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);
    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);
  }
}

           
         
  








Related examples in the same category

1.JToolBar: addPropertyChangeListener(PropertyChangeListener listener)
2.JToolBar: addSeparator()
3.JToolBar: getOrientation()
4.JToolBar: isFloatable()
5.JToolBar: setFloatable(boolean b)
6.JToolBar: setRollover(boolean v)