Overflow one row in FlowLayout - Java Swing

Java examples for Swing:FlowLayout

Introduction

FlowLayout tries to lay out all components in only one row.

Demo Code

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Main {
  public static void main(String[] argv) throws Exception {
    JFrame frame = new JFrame("flow layout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new FlowLayout());

    for (int i = 1; i <= 30; i++) {
      frame.getContentPane().add(new JButton("Button " + i));
    }//  ww w .ja  va2 s .  c om

    frame.pack();
    frame.setVisible(true);

  }
}

Related Tutorials