- Trending Categories
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 FlowLayout for JFrame in Java?
To set FlowLayout for a frame, use the Container. At first, set a JFrame −
JFrame frame = new JFrame();
Now, use Container and set the layout as FlowLayout−
Container container container = frame.getContentPane(); container.setLayout(new FlowLayout());
The following is an example to set FlowLayout for JFrame −
Example
package my; import java.awt.Container; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; public class SwingDemo { public static void main(String[] val) { JFrame frame = new JFrame(); Container container; JButton btn; frame.setBounds(20, 20, 15, 15); container = frame.getContentPane(); container.setLayout(new FlowLayout()); btn = new JButton("Submit"); JCheckBox checkBox1 = new JCheckBox("Graduate"); JCheckBox checkBox2 = new JCheckBox("Post-Graduate"); container.add(btn); container.add(checkBox1); container.add(checkBox2); frame.setVisible(true); frame.setSize(550, 400); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); } }
Output
- Related Articles
- How to set default button for JFrame in Java?
- How to set minimum size limit for a JFrame in Java
- How to set location of JLabel in a JFrame with Java?
- How to combine FlowLayout and BoxLayout in Java?\n
- How to maximize JFrame in Java Swing
- How to activate and deactivate JFrame in Java
- How to change JFrame background color in Java
- How to add background Image to JFrame in Java
- How to set the location of a button anywhere in JFrame?
- How to arrange components in a FlowLayout to be left-justified in Java?
- How to disable close button on a JFrame in Java?
- How to create a Titleless and Borderless JFrame in Java?
- Program to combine BorderLayout, GridLayout and FlowLayout in Java Swing?
- How to set JAVA_HOME for Java in Windows?
- How to set JAVA_HOME for Java in Linux?

Advertisements