Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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

Advertisements