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");
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//code to create a JToolBar 
    JToolBar toolbar = new JToolBar();
    toolbar.setRollover(true);

    
    JButton button = new JButton("New File");
    toolbar.add(button);
    toolbar.addSeparator();
    
    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);
            this.setLocationRelativeTo(null);
          setVisible(true);
 
 }
    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

COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators 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 php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: How to create a JToolBar Java Example
How to create a JToolBar Java Example
https://4.bp.blogspot.com/-MtJne2PrjTw/WZ9b1b5hbsI/AAAAAAAAIgU/Ihmrt6EnTGYO0UQStKj-lxTH9tp4j52agCLcBGAs/s200/JtoolBar_Example-min.PNG
https://4.bp.blogspot.com/-MtJne2PrjTw/WZ9b1b5hbsI/AAAAAAAAIgU/Ihmrt6EnTGYO0UQStKj-lxTH9tp4j52agCLcBGAs/s72-c/JtoolBar_Example-min.PNG
Java Codes
http://www.download-all.net/2017/08/how-to-create-jtoolbar-java-example.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/08/how-to-create-jtoolbar-java-example.html
true
7826648292785071009
UTF-8
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