Swingexamples-example-of-flowlayout

提供:Dev Guides
移動先:案内検索

Swingの例-フローレイアウト

クラス FlowLayout は、コンポーネントを左から右のフローに配置します。

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class SwingTester {
   public static void main(String[] args) {
      createWindow();
   }

   private static void createWindow() {
      JFrame frame = new JFrame("Swing Tester");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      createUI(frame);
      frame.setSize(560, 200);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
   }

   private static void createUI(final JFrame frame){
      JPanel panel = new JPanel();
      FlowLayout layout = new FlowLayout();

      panel.setLayout(layout);
      panel.add(new JButton("Button 1"));
      panel.add(new JButton("Button 2"));
      panel.add(new JButton("Button 3"));
      panel.add(new JButton("Button 4"));
      panel.add(new JButton("Button 5"));
      frame.getContentPane().add(panel, BorderLayout.CENTER);
   }
}

出力

FlowLayoutの使用 link:/cgi-bin/printpage.cgi [__ Print]