PHP字串長度找子字串與取代字串的常用函數

PHP在字串的操作上,有非常多的相關函數可以使用,我們在這裡只介紹經常會使用到的字串操作函數。像是如何取得字串的長度、在某一個字裏面尋找子字串首次出現的位置、以及字串的取代函數...等等。這些都是在編寫程式的時候,頻繁被程式設計師使用到的基礎函數。 取得字串長度 <?...

2017年12月24日 星期日

運用FlowLayout來依序排列元件,超出列宽往下一列放置元件


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);		
	}

}

執行結果

1 則留言: