TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Java Swing

Java Swing FlowLayout

Overview

In this tutorial, we will learn about Java Swing FlowLayout.
FlowLayout is the default layout for the JPanel container. It is the simplest layout in Java Swing layouts.

Java Swing FlowLayout

The FlowLayout places GUI components from left to right in a row until no space is available in the container. When no space is available, a new row is started in the container. The place of the component depends on the size of the container therefore you cannot guarantee which row the component is placed.

Java Demo Program

import java.awt.*;
import javax.swing.*;

/****************************************
 * Filename: FlowLayoutDemo.java
 * 
 * Java Tutorials - www.TestingDocs.com
 *****************************************/

public class FlowLayoutDemo {
 
 public static void main(String[] args) {

 JFrame frame = new JFrame("FlowLayout -www.TestingDocs.com");
 JButton btn1 = new JButton("Button 1");
 JButton btn2 = new JButton("Button 2");
 JButton btn3 = new JButton("Button 3");
 JButton btn4 = new JButton("Button 4");
 JButton btn5 = new JButton("Button 5");
 JButton btn6 = new JButton("Button 6");
 JButton btn7 = new JButton("Button 7");
 JButton btn8 = new JButton("Button 8");
 // FlowLayout
 JPanel panel = new JPanel(new FlowLayout());
 // add the buttons 
 panel.add(btn1);
 panel.add(btn2);
 panel.add(btn3);
 panel.add(btn4);
 panel.add(btn5);
 panel.add(btn6);
 panel.add(btn7);
 panel.add(btn8);

 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 frame.setSize(400,200);
 frame.getContentPane().add(panel);
 frame.setVisible(true);
 }
}

Output

Run the Java application to view the output.

Java Swing FlowLayout

 

—

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/in/java/

Related Posts

Add GUI Components Swing

Java Swing /

Add GUI Components to a Swing Container

JPanel Container Class

Java Swing /

Swing JPanel Container Class

Swing CardLayout

Java Swing /

Java Swing CardLayout

Java Swing GridLayout

Java Swing /

Java Swing GridLayout

Java Swing BorderLayout

Java Swing /

Java Swing BorderLayout

‹ Java Swing BorderLayout› Java Swing GridLayout

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version