package test.swing.layout; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; public class TestFlowLayout extends JFrame { private JPanel contentPane; public static void main(String[] args) { TestFlowLayout frame = new TestFlowLayout(); frame.setVisible(true); } public TestFlowLayout() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); //(左邊界,上邊界,宽度,長度) contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); //(上,左,下,右) setContentPane(contentPane); //將Layout設定為由左至右的排列components之間的關係,超出面板宽度的元件往下列遞補 contentPane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); //(置左,左右間距,上下間距) JButton firstBtn = new JButton("按鈕 1"); contentPane.add(firstBtn); JButton secondBtn = new JButton("按鈕 2"); contentPane.add(secondBtn); JButton thirdBtn = new JButton("按鈕 3"); contentPane.add(thirdBtn); JButton forthBtn = new JButton("按鈕 4"); contentPane.add(forthBtn); JButton fifthBtn = new JButton("按鈕 5"); contentPane.add(fifthBtn); JButton sixthBtn = new JButton("按鈕 6"); contentPane.add(sixthBtn); } }
執行結果
用于编程的java编程示例
回覆刪除java示例代码获取servlet会话时间信息