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

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

2017年12月24日 星期日

使用GridBagLayout將每個元件放入每一格子裡面

package test.swing.layout;

import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class TestGridLayout extends JFrame {
 
 private JPanel contentPane;

 public static void main(String[] args) {
  TestGridLayout frame = new TestGridLayout();
  frame.setVisible(true);
 }
 
 public TestGridLayout() {
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setBounds(100, 100, 450, 300);   //(左邊界,上邊界,宽度,長度)
  contentPane = new JPanel();
  contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));   //(上,左,下,右)
  setContentPane(contentPane);
  
  //將Layout設定為GridLayout會把視窗畫面切割成長、宽相同大小的方格
  contentPane.setLayout(new GridLayout(2, 0, 10, 5));  //(列數,欄數,左右間距,上下間距)
  
  JButton firstBtn = new JButton("按鈕 1");
  contentPane.add(firstBtn);
  
  JButton secondBtn = new JButton("按鈕 2");
  contentPane.add(secondBtn);
  
  JButton thirthBtn = new JButton("按鈕 3");
  contentPane.add(thirthBtn); 
  
  JButton forthBtn = new JButton("按鈕 4");
  contentPane.add(forthBtn); 
 }

}

執行結果

沒有留言:

張貼留言