註冊
登錄
論壇
搜索
幫助
導航
私人消息 (0)
公共消息 (0)
系統消息 (0)
好友消息 (0)
帖子消息 (0)
種子論壇 | 高雄市資訊培育協會學員討論區
»
結訓課程 (青少年程式設計班)
»
Java(五1930)
» 佈局元件 - FlowLayout
返回列表
發帖
發短消息
加為好友
tonyh
當前離線
UID
94
帖子
7024
精華
21
積分
210
閱讀權限
150
在線時間
2581 小時
註冊時間
2011-1-8
最後登錄
2024-9-19
超級版主
1
#
跳轉到
»
倒序看帖
打印
字體大小:
t
T
tonyh
發表於 2017-9-8 21:17
|
只看該作者
佈局元件 - FlowLayout
本帖最後由 tonyh 於 2019-9-7 14:51 編輯
運用 FlowLayout 佈局需留意以下事項:
1. 若容器被設為FlowLayout,被丟入的元件無法設定位置與大小,大小將依內容而改變。
2. FlowLayout 對齊方式預設為置中對齊,而物件之間的水平及垂直間距皆預設為5像素。
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
public class Ch113 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch113()
{
JButton btn1=new JButton("xxx");
//btn1.setBounds(0, 0, 100, 100);
//btn1.setSize(100, 100);
//若容器被設為FlowLayout,被丟入的元件則無法設定位置與大小,大小將依內容而改變
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("FlowLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 10)); //靠左對齊、水平間距5、垂直間距10
//new FlowLayout() 對齊方式預設為置中對齊,而物件之間的水平及垂直間距皆預設為5像素
fm.add(btn1);
fm.add(btn2);
fm.add(btn3);
fm.add(btn4);
fm.add(btn5);
fm.add(btn6);
}
public static void main(String[] args) {
new Ch113();
}
}
複製代碼
收藏
分享
發短消息
加為好友
黃璽安
(Andy)
當前離線
UID
67668
帖子
385
精華
0
積分
0
閱讀權限
100
在線時間
85 小時
註冊時間
2015-1-29
最後登錄
2024-1-31
版主
2
#
黃璽安
發表於 2017-9-9 15:30
|
只看該作者
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
public class Ch111 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch111()
{
JButton btn1=new JButton("xxx");
btn1.setBounds(0,0,100,100);
btn1.setSize(100,100);
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");
JFrame fm=new JFrame("FlowLayout");
fm.setBounds(100,100,300,200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 10));
fm.add(btn1);
fm.add(btn2);
fm.add(btn3);
fm.add(btn4);
fm.add(btn5);
fm.add(btn6);
}
public static void main(String[] args) {
new Ch111();
}
}
複製代碼
TOP
發短消息
加為好友
洪振庭
當前離線
UID
67646
帖子
394
精華
0
積分
0
閱讀權限
10
在線時間
103 小時
註冊時間
2014-6-30
最後登錄
2020-1-4
新手上路
3
#
洪振庭
發表於 2017-9-11 20:16
|
只看該作者
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
public class Ch113 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch113()
{
JButton btn1=new JButton("x 456 x");
JButton btn3=new JButton(" ______/* ____ ");
JButton btn4=new JButton("_____ _______________");
JButton btn5=new JButton(" 1 1 1 ");
JButton btn6=new JButton(" 1 1 4 1 4 ");
JButton btn2=new JButton(" 1 8 7 12 ");
fm=new JFrame("FlowLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 10));
fm.add(btn1);
fm.add(btn2);
fm.add(btn3);
fm.add(btn4);
fm.add(btn5);
fm.add(btn6);
}
public static void main(String[] args) {
new Ch113();
}
}
複製代碼
TOP
發短消息
加為好友
陳思惟
當前離線
UID
67672
帖子
336
精華
0
積分
15
閱讀權限
10
在線時間
100 小時
註冊時間
2015-1-29
最後登錄
2021-7-28
新手上路
4
#
陳思惟
發表於 2017-9-15 20:07
|
只看該作者
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
public class Ch113 {
JFrame fm;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
Ch113()
{
JButton btn1=new JButton("xxx");
//btn1.setBounds(0, 0, 100, 100);
//btn1.setSize(100, 100);
//若容器被設為FlowLayout,被丟入的元件則無法設定位置與大小,大小將依內容而改變
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("FlowLayout");
fm.setBounds(100, 100, 300, 200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 10)); //靠左對齊、水平間距5、垂直間距10
//new FlowLayout() 對齊方式預設為置中對齊,而物件之間的水平及垂直間距皆預設為5像素
fm.add(btn1);
fm.add(btn2);
fm.add(btn3);
fm.add(btn4);
fm.add(btn5);
fm.add(btn6);
}
public static void main(String[] args) {
new Ch113();
}
}
複製代碼
TOP
發短消息
加為好友
李知易
當前離線
UID
67631
帖子
589
精華
0
積分
0
閱讀權限
10
在線時間
152 小時
註冊時間
2014-6-30
最後登錄
2022-6-7
新手上路
5
#
李知易
發表於 2017-9-15 20:30
|
只看該作者
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
public class Ch104 {
JFrame fm;
JButton b1,b2,b3,b4,b5,b6;
Ch104()
{
JButton b1=new JButton("我換換");
b1.setBounds(0,0,100,100);
b1.setSize(100,100);
JButton b2=new JButton("我換換換");
JButton b3=new JButton("我換換換換");
JButton b4=new JButton("我換換換換換");
JButton b5=new JButton("我換換換換換換");
JButton b6=new JButton("我換換換換換換換");
JFrame fm=new JFrame("FlowLayout");
fm.setBounds(100,100,300,200);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 10));
fm.add(b1);
fm.add(b2);
fm.add(b3);
fm.add(b4);
fm.add(b5);
fm.add(b6);
}
public static void main(String[] args) {
new Ch104();
}
}
複製代碼
EEEEEEEEEEEEELLLLLLLLLLLLLIIIIIIIIIIIII
TOP
返回列表
谷哥人營隊
113Scratch夏令營
113年APCS冬令營
113年Scratch冬令營
113年Python研習冬令營
113年Python證照特訓營(一)
113年谷哥人程式體驗營
113年國三專班
113年Python研習夏令營
113年Python證照特訓營(二)
113年程式夏令營(一)(二)
113年APCS夏令營(一)(二)
112年國三專班
112APCS夏令營(一)(二)
112App快速開發夏令營
C語言 / C++ (特別輔導)
C++證照
C#
家教特輔
C語言特輔/證照(家教)
C++證照
C#
HTML5+CSS+JavaScript+PHP+MySQL
Java 家教 (王捷恩)
113新版塊名稱
快樂學 Scratch
Python 家教 (王捷恩 康恒睿)
Python 特別輔導 (家教)
快樂 C++ (家教)
我愛 Java (家教)
程式解題我最行 (家教)
程式常態班
C++ 新生挑戰區
考照心得分享
快樂 C++11307週五19:00
快樂 C++11303 (週六15:40-17:40) 3F
程式解題我最行 (週六15:30-17:30) 3F
快樂 C++ (週六13:30-15:30) 3F
快樂 C++ (週六19:00-21:00) 3F
程式解題我最行 (週六10:00-12:00) 3F
快樂學 Scratch
程式解題我最行(週五19:00-21:00)
快樂 C++ (週六13:30-15:30) 3F
程式解題我最行(週三19:15-21:15)
快樂 C++11207週六10
快樂 C++11208週六19:00
程式解題我最行 (週五19:00-21:00) 3F
快樂 C++ (週六15:30-17:30) 3F
程式解題我最行 (週六19:00-21:00) 3F
程式解題我最行 (週四19:10-21:10)
產投職訓
結訓課程 (產投職訓)
Php & MySQL old
Illustrator old
Dreamweaver old
Android手機程式開發班
PHP & MySQL電子商務互動式網站實作班 (102下)
PHP & MySQL (102上)
PHP & MySQL電子商務互動式網站實作班
Photoshop數位影像設計初階
Flash創意廣告動畫初階
行銷短片視訊剪輯
數位商業攝影實務班
PHP & MySQL電子商務系統開發實務初階班
電子商務系統開發實務中階班
Server基礎架設&動態網頁設計初階班
Java視窗應用程式設計與遊戲開發班
Illustrator時尚插畫創作設計初階班
102上Php & MySQL 初階班
電子商務互動式網站實作中階
Dreamweaver多媒體網頁設計
Android手機程式開發班(2012年10月)
PHP & MySQL (2012年10月)
創意塗鴉
yahoo橫幅
google橫幅
市民學苑
第二屆樂活部落格
第一屆電腦設備簡易維護和故障排除班
專案訓練
電子商務創業班
TQC PHP認證
投資理財班
領隊導遊班
電腦基礎及網路應用身心障礙專班
應用軟體網頁化開發
[收藏此主題]
[關注此主題的新回復]
[通過 QQ、MSN 分享給朋友]