標題:
佈局元件 - BorderLayout 搭配 GridLayout
[打印本頁]
作者:
tonyh
時間:
2020-9-7 19:30
標題:
佈局元件 - BorderLayout 搭配 GridLayout
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JPanel;
public class Ch116 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
JPanel pn1,pn2;
Ch116()
{
btn1=new JButton("xxx");
btn2=new JButton("xxxxxxx");
btn3=new JButton("xxxxxxxxxxx");
btn4=new JButton("xxxxxxxxx xxxxxxx");
btn5=new JButton("xxx");
btn6=new JButton("x");
pn1=new JPanel();
pn1.setLayout(new GridLayout(4,1,5,5));
pn1.add(btn1);
pn1.add(btn2);
pn1.add(btn3);
pn1.add(btn4);
pn2=new JPanel();
pn2.setLayout(new GridLayout(2,1));
pn2.add(btn5);
pn2.add(btn6);
fm=new JFrame("BorderLayout 搭配 GridLayout");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout());
fm.add(pn1,BorderLayout.WEST);
fm.add(pn2,BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch116();
}
}
複製代碼
作者:
黃宇瑄
時間:
2020-9-7 19:54
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JPanel;
public class Ch01 {
JFrame fm;
JButton b1,b2,b3,b4,b5,b6;
JPanel pn1,pn2;
Ch01()
{
b1=new JButton("xxxxx xxxxxxx");
b2=new JButton("xx xxxx xxxxxx x");
b3=new JButton("xxx xx xxx");
b4=new JButton("xxx xxxxx xxxxx x xx");
b5=new JButton("x");
b6=new JButton("x x");
pn1=new JPanel();
pn1.setLayout(new GridLayout(4,1,5,5));
pn1.add(b1);
pn1.add(b2);
pn1.add(b3);
pn1.add(b4);
pn2=new JPanel();
pn2.setLayout(new GridLayout(2,1));
pn2.add(b5);
pn2.add(b6);
fm=new JFrame("BorderLayout 搭配 GridLayout");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout());
fm.add(pn1,BorderLayout.WEST);
fm.add(pn2,BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch01();
}
}
複製代碼
作者:
戴嘉禾
時間:
2020-9-7 19:56
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JPanel;
public class Ch01 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
JPanel pn1,pn2;
Ch01()
{
btn1=new JButton("xxx");
btn2=new JButton("xxxxxxx");
btn3=new JButton("xxxxxxxxxxx");
btn4=new JButton("xxxxxxxxx xxxxxxx");
btn5=new JButton("xxx");
btn6=new JButton("x");
pn1=new JPanel();
pn1.setLayout(new GridLayout(4,1,5,5));
pn1.add(btn1);
pn1.add(btn2);
pn1.add(btn3);
pn1.add(btn4);
pn2=new JPanel();
pn2.setLayout(new GridLayout(2,1));
pn2.add(btn5);
pn2.add(btn6);
fm=new JFrame("BorderLayout 搭配 GridLayout");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new BorderLayout());
fm.add(pn1,BorderLayout.WEST);
fm.add(pn2,BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch01();
}
}
複製代碼
作者:
鄭楀諺
時間:
2020-9-18 19:38
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Ch130 {
JFrame fn;
JButton btn1, btn2, btn3, btn4, btn5, btn6;
JPanel pn1, pn2;
Ch130()
{
btn1 = new JButton("xxx");
btn2 = new JButton("xxxxxxx");
btn3 = new JButton("xxxxxxxxxxx");
btn4 = new JButton("xxxxxxxxx xxxxxxx");
btn5 = new JButton("xxx");
btn6 = new JButton("x");
pn1 = new JPanel();
pn1.setLayout(new GridLayout(4, 1, 5, 5));
pn1.add(btn1);
pn1.add(btn2);
pn1.add(btn3);
pn1.add(btn4);
pn2 = new JPanel();
pn2.setLayout(new GridLayout(2, 1));
pn2.add(btn5);
pn2.add(btn6);
fn = new JFrame("Grid");
fn.setBounds(100, 100, 300, 200);
fn.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fn.setVisible(true);
fn.setLayout(new BorderLayout(5, 5));
fn.add(pn1, BorderLayout.WEST);
fn.add(pn2, BorderLayout.EAST);
}
public static void main(String[] args) {
new Ch130();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2