Pin It

How to use FlowLayout in Java using Swing ?.

A Simple Java Program demonstrating a way to use FlowLayout layout using Swing API.

package com.hubberspot.swing.example;

import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class FlowLayoutDemo extends JFrame {
  public FlowLayoutDemo() {
    setLayout(new FlowLayout());
    for(int i = 0; i < 20; i++){
 add(new JButton("Button " + i));
 JTextField textfield= new JTextField();
 textfield.setEditable(false);
 textfield.setText("TextField " + (i));
 add(textfield);
    }
  }
  public static void main(String[] args) {
    setFrame(new FlowLayoutDemo(), 400, 400);
  }

  public static void 
  setFrame(final JFrame frame, final int width, final int height) {
     SwingUtilities.invokeLater(new Runnable() {
 public void run() {
          frame.setTitle(frame.getClass().getSimpleName());
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setSize(width, height);
   frame.setVisible(true);
 }
    });
 }
} 

Output of the program : 


 
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot