Java Reference
In-Depth Information
Component
2
Component
3
Component
1
Component
4
FIGURE 7.7
Flow layout puts as many components as possible on a row
LISTING 7.20
//********************************************************************
// FlowPanel.java Author: Lewis/Loftus
//
// Represents the panel in the LayoutDemo program that demonstrates
// the flow layout manager.
//********************************************************************
import
java.awt.*;
import
javax.swing.*;
public class
FlowPanel
extends
JPanel
{
//-----------------------------------------------------------------
// Sets up this panel with some buttons to show how flow layout
// affects their position.
//-----------------------------------------------------------------
public
FlowPanel ()
{
setLayout (
new
FlowLayout());
setBackground (Color.green);
JButton b1 =
new
JButton ("BUTTON 1");
JButton b2 =
new
JButton ("BUTTON 2");
JButton b3 =
new
JButton ("BUTTON 3");
JButton b4 =
new
JButton ("BUTTON 4");
JButton b5 =
new
JButton ("BUTTON 5");
Search WWH ::
Custom Search