How to create a JToolBar Java Example

A JToolBar mainly comprises of JButtons components which can also be separated by a JSeperators.A JToolBar can be inserted in any four...

How to create a JToolBar Java Example
A JToolBar mainly comprises of JButtons components which can also be separated by a JSeperators.A JToolBar can be inserted in any four corners of a JPanel or can also be made to float.
Generally, JToolBar uses BoxLayout which assumes objects height or width and arranges them vertically or horizontally.
To align a JToolBar  call class setAlignmentX() or setAligmentY().

JToolBar Constructors.

  • JToolBar()-Creates a new JToolBar with default orientation Horizontal.
  • JToolBar(int orientation)-Creates a new JToolBar with specified Orientation.
  • JToolBar(String name)-creates a JToolBar with the specified name.
  • JToolBar(int orientation,String name)-creates aJToolBar with orientation and name.

JToolBar Code Example

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
public class JToolBarExample extends JFrame{

 public JToolBarExample()
     super("JToolBar Example");
//code to create a JToolBar 
    JToolBar toolbar = new JToolBar();

    JButton button = new JButton("New File");
    toolbar.add(new JButton("Save File"));
    toolbar.add(new JComboBox(new String[]{"Sales Report","Items Report","Customers Report"}));
    Container pane = this.getContentPane();
    pane.add(toolbar, BorderLayout.NORTH);
    JTextArea textArea = new JTextArea();
    JScrollPane Jpane = new JScrollPane(textArea);
             pane.add(Jpane, BorderLayout.CENTER);
            setSize(350, 150);
    public static void main(String[] args) {
        // TODO code application logic here
        new JToolBarExample();

See also:

How to create a JToolBar with a  drop-down menu as one of the items



android android Apps android emulators antivirus arrays blogger bluestack Break Statement in Java constructors download downloader drivers emulators fragment java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql node.js php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
Java Codes: How to create a JToolBar Java Example
How to create a JToolBar Java Example
Java Codes
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy