This is a Java Program to Create a Group of Right Justified Buttons and Arrange them in Container using Flow Layout Manager
We have to write a program in Java such that it creates a frame with few buttons which are right justified using the Flow Layout Manager.
For creating frame with right justified buttons, we have the following set of input and output.
1. When the frame is created :
On the execution of the program, it is expected that a frame appears with a few right justified buttons. Buttons - Button 1, Button 2, Button 3
1. Create a frame and few buttons.
2. Set the layout of frame as FlowLayout with alignment of components as RIGHT
3. Display the frame.
Here is source code of the Java Program to create right justified buttons. The program is successfully compiled and tested using javac compiler on Fedora 30. The program output is also shown below.
/*Java Program to create right justified buttons and
arrange in conatiner using Flow Layout Manager*/
public static void main(String args)
//Create a frame
JFrame frame = new JFrame("Buttons");
//Set the layout of frame as right aligned flow layout
//Create 3 push buttons
JButton button = new JButton;
button[i]=new JButton("Button "+(i+1));
//Display the frame
1. Set the layout of frame as FlowLayout.
2. Set the alignment of the layout as FlowLayout.RIGHT. This ensures that all the components are right aligned.
Here’s the run time test case for creating a frame with right justified buttons.
Sanfoundry Global Education & Learning Series – Java Programs.