Java Tutorial
In java programming, we can also use flow layout in JFrame to create a Graphical user interface (GUI) using JFrame class.
In Java JFrame, need to set the layout to add the components.
Flow Layout is used to put the components from left to right and then next line in the JFrame.
We can also say, arranging the components in sequence.
setLayout(new FlowLayout());
// importing swing package for JFrame, Jbutton controls import javax.swing.*; // importing to use Container class import java.awt.*; public class FlowLayoutTest extends JFrame { public FlowLayoutTest(){ // Setting Title to the JFrame GUI setTitle("Flow Layout Test Java Code"); // Setting flow layout to JFrame GUI setLayout(new FlowLayout()); // Adding buttons using Flow Layout add(new JButton("Button1")); add(new JButton("Button2")); add(new JButton("Button3")); add(new JButton("Button4")); } public static void main(String[] args){ // Create JFrame for GUI frame and title as 'Add Button in JFrame Java Code' FlowLayoutTest frame = new FlowLayoutTest(); frame.setSize(500,200); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }Output:
Once executing this java program, Frame with flow layout buttons will be popped up as above and closes if we click close button in the frame title.
Java Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page