Java by API/java.awt/FlowLayout

Материал из Java эксперт
Перейти к: навигация, поиск

FlowLayout.LEFT

   <source lang="java">

import java.awt.Container; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; public class MainClass {

 public static void main(String[] args) {
   JFrame aWindow = new JFrame();
   aWindow.setBounds(200, 200, 200, 200);
   aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   Container content = aWindow.getContentPane();
   content.setLayout(new FlowLayout(FlowLayout.LEFT));
   content.add(new JButton("www.jexp.ru"));
   content.add(new JLabel("www.jexp.ru"));
   content.add(new JTextField("www.jexp.ru"));
   aWindow.setVisible(true);
 }

}


 </source>
   
  
 
  



FlowLayout.RIGHT

   <source lang="java">

/*

* Output:
*  
*/

import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class MainClass extends JPanel {

 public MainClass() {
   super(new FlowLayout(FlowLayout.RIGHT, 10, 3));
   add(new JButton("w w w.j a v a 2 s . c o m"));
   add(new JButton("w w w.j a v a 2 s . com"));
   add(new JButton("w w w.jexp.ru"));
   add(new JButton("www.j ava 2 s . c o m"));
 }
 public static void main(String[] args) {
   JFrame frame = new JFrame();
   frame.getContentPane().add(new MainClass());
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setSize(200, 200);
   frame.setVisible(true);
 }

}


 </source>
   
  
 
  



new FlowLayout(int align)

   <source lang="java">

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"));
 }

}

 </source>
   
  
 
  



new FlowLayout(int align, int hgap, int vgap)

   <source lang="java">

/*

* Output:
*  
*/

import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class MainClass extends JPanel {

 public MainClass() {
   super(new FlowLayout(FlowLayout.RIGHT, 10, 3));
   add(new JButton("w w w.j a v a 2 s . c o m"));
   add(new JButton("w w w.j a v a 2 s . com"));
   add(new JButton("w w w.jexp.ru"));
   add(new JButton("www.j ava 2 s . c o m"));
 }
 public static void main(String[] args) {
   JFrame frame = new JFrame();
   frame.getContentPane().add(new MainClass());
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setSize(200, 200);
   frame.setVisible(true);
 }

}


 </source>