FileDocCategorySizeDatePackage
FlowLayoutDemo.javaAPI DocExample1338Sun Jan 07 16:43:46 GMT 2001None

FlowLayoutDemo.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

 public class FlowLayoutDemo extends JFrame {

  public FlowLayoutDemo() {
    super("FlowLayoutDemo");

    Container contentPane = getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(new JButton("OK"));
    contentPane.add(new JButton("Cancel"));

    applyOrientation(this, ComponentOrientation.RIGHT_TO_LEFT);
  }

  public static void main(String [] argv) {
    JFrame frame = new FlowLayoutDemo();
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {System.exit(0);}
    });

    frame.pack();
    frame.setVisible(true);
  }

  /*
  ** applyOrientation():
  ** Borrowed from SwingApplet demo!
  */
  private void applyOrientation(Component c, ComponentOrientation o)  {
    c.setComponentOrientation(o);

    if (c instanceof JMenu) {
      JMenu menu = (JMenu)c;
      int ncomponents = menu.getMenuComponentCount();
      for (int i = 0; i < ncomponents; ++i) {
        applyOrientation(menu.getMenuComponent(i), o);
      }
    } else if (c instanceof Container) {
      Container container = (Container)c;
      int ncomponents = container.getComponentCount();
      for (int i = 0; i < ncomponents; ++i) {
        applyOrientation(container.getComponent(i), o);
      }
    }
  }
}