流程佈局
import javax.swing.*;
import java.awt.FlowLayout;
public class FlowExample {
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(new JButton("One"));
panel.add(new JButton("Two"));
panel.add(new JButton("Three"));
panel.add(new JButton("Four"));
panel.add(new JButton("Five"));
JFrame frame = new JFrame();
frame.setContentPane(Panel);
frame.pack();
frame.setVisible(true);
}
});
}
}
Flow 佈局是 Swing 提供的最簡單的佈局管理器。流佈局嘗試將所有內容放在一行上,如果佈局溢位寬度,它將包裹該行。訂單由你向面板新增元件的訂單指定。
截圖: