Tuesday, September 30, 2008

FLOWLAYOUT

FlowLayout.LEFT
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.java.com"));
content.add(new JLabel("www.java.com"));
content.add(new JTextField("www.java.com"));
aWindow.setVisible(true);
}
}

FlowLayout.RIGHT
/* *
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 . c o m"));
add(new JButton("w w w.j a v a . c o m"));
add(new JButton("w w w.j a v a.c o m"));
add(new JButton("www.j a v a.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);
}
}

No comments: