Java Program to create Arrow Button positioning North

Java 8Object Oriented ProgrammingProgramming

To create Arrow Button at position north, use BasicArrowButton:

BasicArrowButton arrow = new BasicArrowButton(BasicArrowButton.NORTH);

Above, we have set the arrow to NORTH. Now add it to Panel:

panel.add(arrow, BorderLayout.NORTH);

The following is an example to create Arrow Button positioning North:

Example

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.plaf.basic.BasicArrowButton;
public class SwingDemo extends JPanel {
   public SwingDemo() {
      setLayout(new BorderLayout());
      JPanel panel = new JPanel(new BorderLayout());
      add(panel, BorderLayout.EAST);
      BasicArrowButton arrow = new BasicArrowButton(BasicArrowButton.NORTH);
      panel.add(arrow, BorderLayout.NORTH);
   }
   public static void main(String[] args) {
      JFrame frame = new JFrame("Frame with arrow");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.add(new SwingDemo());
      frame.setSize(600, 500);
      frame.setLocationByPlatform(true);
      frame.setVisible(true);
   }
}

The output is as follows displaying the arrow button positioning NORTH:

raja
Published on 03-May-2019 10:58:27
Advertisements