//FlowLayout,Panel类的默认布局管理器 import java.awt.*; public class TestLayout { public static void main(String[] args) { Frame f = new Frame("Flow Layout"); Button b1 = new Button("OK"); Button b2 = new Button("Open"); Button b3 = new Button("Close"); f.setLayout(new FlowLayout()); //f.setLayout(new FlowLayout(FlowLayout.LEFT)); //f.setLayout(new FlowLayout(FlowLayout.LEFT,40,50)); f.add(b1); f.add(b2); f.add(b3); f.setSize(100, 100); f.setVisible(true); } }
//FlowLayout import java.awt.*; public class TestFlowLayout2 { public static void main(String[] args) { Frame f = new Frame("java Frame"); FlowLayout l = new FlowLayout(FlowLayout.CENTER, 20, 40); f.setLayout(l); f.setLocation(300, 400); f.setSize(300, 200); f.setBackground(new Color(204, 204, 255)); for(int i = 0; i <= 7; i++) { f.add(new Button("BUTTON")); } f.setVisible(true); } }
来源:https://www.cnblogs.com/wjchang/archive/2012/05/06/3671620.html