流程布局
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 提供的最简单的布局管理器。流布局尝试将所有内容放在一行上,如果布局溢出宽度,它将包裹该行。订单由你向面板添加组件的订单指定。
截图: