Set to Flow from left for FlowLayout in Java

Description

The following code shows how to set to Flow from left for FlowLayout.

Example


// w  ww  .  j  a  v  a 2  s  .com
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 Main extends JFrame {

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

  public Main() {
    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"));
  }

}

The code above generates the following result.

Set to Flow from left for FlowLayout in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer