How to create a vertical toolbar in Java?



Let us first create a toolbar −

JToolBar toolbar = new JToolBar();

Now, set the orientation to create vertical toolbar −

toolbar.setOrientation(SwingConstants.VERTICAL);

The following is an example to create a vertical toolbar in Java −

package my; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JToolBar; import javax.swing.SwingConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       JToolBar toolbar = new JToolBar();       toolbar.setOrientation(SwingConstants.VERTICAL);       toolbar.add(new JTextArea());       toolbar.add(new JButton("Submit"));       frame.add(toolbar,BorderLayout.WEST);       frame.setTitle("Vertical ToolBar");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       //frame.setLocationByPlatform(true);       frame.setSize(550, 400);       frame.setVisible(true);    } }

Output

Updated on: 2019-07-30T22:30:26+05:30

539 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements