How to create a vertical toolbar in Java?

Java 8Object Oriented ProgrammingProgramming

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

raja
Published on 31-May-2019 11:33:20
Advertisements