FlowLayout Behavior : FlowLayout « Swing « Java Tutorial






FlowLayout Behavior
import java.awt.Container;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class FlowLayoutBehaviour extends JFrame {

  public static void main(String[] args) {
    FlowLayoutBehaviour ft = new FlowLayoutBehaviour();
    ft.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ft.setSize(400, 300);
    ft.setVisible(true);
  }

  public FlowLayoutBehaviour() {
    super();
    Container pane = getContentPane();
    pane.setLayout(new FlowLayout(FlowLayout.LEFT));
    pane.add(new JLabel("This is a test"));
    pane.add(new JButton("of a FlowLayout"));
    pane.add(new JTextField(30));
    pane.add(new JTextArea("This is a JTextArea", 3, 10));
    pane.add(new JLabel("This is a FlowLayout test with a long string"));
  }

}








14.89.FlowLayout
14.89.1.Laying Out Components in a Flow (Left-to-Right, Top-to-Bottom)
14.89.2.Three constructors available for the FlowLayout manager.
14.89.3.Layout manager
14.89.4.FlowLayout: the default layout manager for a JPanel.
14.89.5.FlowLayout BehaviorFlowLayout Behavior
14.89.6.Using FlowLayoutUsing FlowLayout
14.89.7.Changing the GapChanging the Gap
14.89.8.Setting the gaps between components and rows explicitly by calling the setHgap()Setting the gaps between components and rows explicitly by calling the setHgap()
14.89.9.Demonstrates how to fix common alignment problemsDemonstrates how to fix common alignment problems
14.89.10.Use FlowLayout to hold checkBox, Label and TextField