標題:
JPanel 類別與 setBorder() 方法
[打印本頁]
作者:
tonyh
時間:
2017-9-22 20:00
標題:
JPanel 類別與 setBorder() 方法
本帖最後由 tonyh 於 2019-9-7 14:56 編輯
試使用 setBorder() 方法,為容器加上邊框。
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Ch117 {
JPanel pn1,pn2,pn3;
JButton btn[]=new JButton[4];
JFrame fm;
Ch117()
{
for(int i=0; i<4; i++)
btn[i]=new JButton("按鈕"+(i+1));
pn1=new JPanel();
pn1.setBorder(new EtchedBorder());
pn2=new JPanel();
pn2.setBorder(new TitledBorder("第二區"));
pn3=new JPanel();
pn3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
pn3.setLayout(new GridLayout(4,1,5,5));
for(int i=0; i<4; i++)
pn3.add(btn[i]);
fm=new JFrame("JPanel & setBorder()");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout());
fm.add(pn1);
fm.add(pn2);
fm.add(pn3);
}
public static void main(String[] args) {
new Ch117();
}
}
複製代碼
作者:
曾挺桂
時間:
2017-9-22 20:26
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Ch117 {
JPanel pn1,pn2,pn3;
JButton btn[]=new JButton[4];
JFrame fm;
Ch117()
{
for(int i=0; i<4; i++)
btn[i]=new JButton("按鈕"+(i+1));
pn1=new JPanel();
pn1.setBorder(new EtchedBorder());
pn2=new JPanel();
pn2.setBorder(new TitledBorder("第二區"));
pn3=new JPanel();
pn3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
pn3.setLayout(new GridLayout(4,1,5,5));
for(int i=0; i<4; i++)
pn3.add(btn[i]);
fm=new JFrame("JPanel & setBorder()");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout());
fm.add(pn1);
fm.add(pn2);
fm.add(pn3);
}
public static void main(String[] args) {
new Ch117();
}
}
複製代碼
作者:
李知易
時間:
2017-9-22 20:33
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Ch108 {
JPanel pn1,pn2,pn3;
JButton btn[]=new JButton[4];
JFrame fm;
Ch108()
{
for(int i=0; i<4; i++)
{
btn[i]=new JButton("按鈕"+(i+1));
}
pn1=new JPanel();
pn1.setBorder(new EtchedBorder());
pn2=new JPanel();
pn2.setBorder(new TitledBorder("第二區"));
pn3=new JPanel();
pn3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
pn3.setLayout(new GridLayout(4,1,5,5));
for(int i=0; i<4; i++)
{
pn3.add(btn[i]);
}
fm=new JFrame("JPanel setBorder()");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout());
fm.add(pn1);
fm.add(pn2);
fm.add(pn3);
}
public static void main(String[] args) {
new Ch108();
}
}
複製代碼
作者:
洪振庭
時間:
2017-9-22 20:36
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Ch117 {
JPanel pn1,pn2,pn;
JButton btn[]=new JButton[4];
JFrame fm;
Ch117()
{
for(int i=0; i<4; i++)
btn[i]=new JButton("按鈕"+(i+1));
pn1=new JPanel();
pn1.setBorder(new EtchedBorder());
pn2=new JPanel();
pn2.setBorder(new TitledBorder("第一區"));
pn=new JPanel();
pn.setBorder(new TitledBorder(null,"第二區",TitledBorder.CENTER,TitledBorder.BOTTOM));
pn.setLayout(new GridLayout(4,1,5,5));
for(int i=0; i<4; i++)
pn.add(btn[i]);
fm=new JFrame("JPanel & setBorder()");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout());
fm.add(pn1);
fm.add(pn2);
fm.add(pn);
}
public static void main(String[] args) {
new Ch117();
}
}
複製代碼
作者:
黃璽安
時間:
2017-9-22 20:46
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Ch110 {
JPanel pn1,pn2,pn3;
JButton btn[]=new JButton[4];
JFrame fm;
Ch110()
{
for(int i=0; i<4; i++)
{
btn[i]=new JButton("按鈕"+(i+1));
}
pn1=new JPanel();
pn1.setBorder(new EtchedBorder());
pn2=new JPanel();
pn2.setBorder(new TitledBorder("第二區"));
pn3=new JPanel();
pn3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
pn3.setLayout(new GridLayout(4,1,5,5));
for(int i=0; i<4; i++)
pn3.add(btn[i]);
fm=new JFrame("JPanew & setBorder()");
fm.setBounds(100,100,450,300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout());
fm.add(pn1);
fm.add(pn2);
fm.add(pn3);
}
public static void main(String[] args) {
new Ch110();
}
}
複製代碼
作者:
陳思惟
時間:
2017-9-29 19:58
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Ch117 {
JPanel pn1,pn2,pn3;
JButton btn[]=new JButton[4];
JFrame fm;
Ch117()
{
for(int i=0; i<4; i++)
btn[i]=new JButton("按鈕"+(i+1));
pn1=new JPanel();
pn1.setBorder(new EtchedBorder());
pn2=new JPanel();
pn2.setBorder(new TitledBorder("第二區"));
pn3=new JPanel();
pn3.setBorder(new TitledBorder(null,"第三區",TitledBorder.CENTER,TitledBorder.BOTTOM));
pn3.setLayout(new GridLayout(4,1,5,5));
for(int i=0; i<4; i++)
pn3.add(btn[i]);
fm=new JFrame("JPanel & setBorder()");
fm.setBounds(100, 100, 450, 300);
fm.setVisible(true);
fm.setResizable(true);
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setLayout(new GridLayout());
fm.add(pn1);
fm.add(pn2);
fm.add(pn3);
}
public static void main(String[] args) {
new Ch117();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2