標題:
佈局元件 - BorderLayout
[打印本頁]
作者:
tonyh
時間:
2019-9-7 15:11
標題:
佈局元件 - BorderLayout
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Ch115 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch115()
{
JButton btn1=new JButton("xxx");
JButton btn2=new JButton("xxxxxxx");
JButton btn3=new JButton("xxxxxxxxxxx");
JButton btn4=new JButton("xxxxxxxxx xxxxxxx");
JButton btn5=new JButton("xxx");
//JButton btn6=new JButton("x");
fm=new JFrame("BorderLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout(5,5));
//如果沒有設Layout,則預設值就是 BorderLayout
//BorderLayout 預設物件之間的水平及垂直距離為0像素
fm.add(btn1, BorderLayout.NORTH);
fm.add(btn2, BorderLayout.SOUTH);
fm.add(btn3, BorderLayout.WEST);
fm.add(btn4, BorderLayout.CENTER);
fm.add(btn5, BorderLayout.EAST);
//fm.add(btn6, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch115();
}
}
複製代碼
作者:
蕭澧邦
時間:
2019-9-21 12:43
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Ch115 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch115()
{
JButton btn1=new JButton("xxx");
JButton btn2=new JButton("xxxxxxx");
JButton btn3=new JButton("xxxxxxxxxxx");
JButton btn4=new JButton("xxxxxxxxx xxxxxxx");
JButton btn5=new JButton("xxx");
//JButton btn6=new JButton("x");
fm=new JFrame("BorderLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout(5,5));
//如果沒有設Layout,則預設值就是 BorderLayout
//BorderLayout 預設物件之間的水平及垂直距離為0像素
fm.add(btn1, BorderLayout.NORTH);
fm.add(btn2, BorderLayout.SOUTH);
fm.add(btn3, BorderLayout.WEST);
fm.add(btn4, BorderLayout.CENTER);
fm.add(btn5, BorderLayout.EAST);
//fm.add(btn6, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch115();
}
}
複製代碼
作者:
黃宥鈞
時間:
2019-9-21 14:14
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Ch115 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch115()
{
JButton btn1=new JButton("xxx");
JButton btn2=new JButton("xxxxxxx");
JButton btn3=new JButton("xxxxxxxxxxx");
JButton btn4=new JButton("xxxxxxxxx xxxxxxx");
JButton btn5=new JButton("xxx");
//JButton btn6=new JButton("x");
fm=new JFrame("BorderLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout(5,5));
//如果沒有設Layout,則預設值就是 BorderLayout
//BorderLayout 預設物件之間的水平及垂直距離為0像素
fm.add(btn1, BorderLayout.NORTH);
fm.add(btn2, BorderLayout.SOUTH);
fm.add(btn3, BorderLayout.WEST);
fm.add(btn4, BorderLayout.CENTER);
fm.add(btn5, BorderLayout.EAST);
//fm.add(btn6, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch115();
}
}
複製代碼
作者:
蔡幸融
時間:
2019-9-21 14:28
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Ch115 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch115()
{
JButton btn1=new JButton("x");
JButton btn2=new JButton("x");
JButton btn3=new JButton("x");
JButton btn4=new JButton("x");
JButton btn5=new JButton("x");
fm=new JFrame("BorderLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout(5,5));
fm.add(btn1, BorderLayout.NORTH);
fm.add(btn2, BorderLayout.SOUTH);
fm.add(btn3, BorderLayout.WEST);
fm.add(btn4, BorderLayout.CENTER);
fm.add(btn5, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch115();
}
}
複製代碼
作者:
高睿辰
時間:
2019-9-21 15:09
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
public class Ch115 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch115()
{
JButton btn1=new JButton("xxx");
JButton btn2=new JButton("xxxxxxx");
JButton btn3=new JButton("xxxxxxxxxxx");
JButton btn4=new JButton("xxxxxxxxx xxxxxxx");
JButton btn5=new JButton("xxx");
//JButton btn6=new JButton("x");
fm=new JFrame("BorderLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout(5,5));
//如果沒有設Layout,則預設值就是 BorderLayout
//BorderLayout 預設物件之間的水平及垂直距離為0像素
fm.add(btn1, BorderLayout.NORTH);
fm.add(btn2, BorderLayout.SOUTH);
fm.add(btn3, BorderLayout.WEST);
fm.add(btn4, BorderLayout.CENTER);
fm.add(btn5, BorderLayout.EAST);
//fm.add(btn6, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch115();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2