![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set all the Arrow Buttons in a frame with Java?
To set arrow buttons in a frame, let us first create a frame −
JFrame frame = new JFrame();
Now, set the layout for the frame wherein all the arrow buttons would be displayed −
frame.setLayout(new GridLayout(0,5));
Set the arrow buttons for all the locations −
frame.add(new BasicArrowButton(BasicArrowButton.EAST)); frame.add(new BasicArrowButton(BasicArrowButton.NORTH)); frame.add(new BasicArrowButton(BasicArrowButton.SOUTH)); frame.add(new BasicArrowButton(BasicArrowButton.WEST));
The following is an example to set all the arrow buttons in a frame −
Example
package my; import java.awt.GridLayout; import javax.swing.Box; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.plaf.basic.BasicArrowButton; public class SwingDemo { public static void main(String[] args) { JButton button1 = new JButton("One"); JButton button2 = new JButton("Two"); JButton button3 = new JButton("Three"); JButton button4 = new JButton("Four"); JButton button5 = new JButton("Five"); JButton button6 = new JButton("Six"); Icon icon = new ImageIcon("E:\editicon.PNG"); JButton button7 = new JButton(icon); Box box = Box.createVerticalBox(); box.add(button1); box.add(button2); box.add(button3); box.add(button4); box.add(button5); box.add(button6); box.add(button7); JFrame frame = new JFrame(); frame.add(box); frame.setLayout(new GridLayout(0,5)); frame.add(new BasicArrowButton(BasicArrowButton.EAST)); frame.add(new BasicArrowButton(BasicArrowButton.NORTH)); frame.add(new BasicArrowButton(BasicArrowButton.SOUTH)); frame.add(new BasicArrowButton(BasicArrowButton.WEST)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationByPlatform(true); frame.setSize(500, 300); frame.setVisible(true); } }
Output
Advertisements