標題:
JPanel 類別與 setBorder() 方法
[打印本頁]
作者:
tonyh
時間:
2019-9-21 15:09
標題:
JPanel 類別與 setBorder() 方法
試使用 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();
}
}
複製代碼
作者:
蔡幸融
時間:
2019-9-21 15:37
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.sql.DriverPropertyInfo;
import java.util.concurrent.BrokenBarrierException;
public class Ch115 {
JFrame fm;
JButton btn1,btn2,btn3,btn4;
JPanel pn1, pn2, pn3;
Ch115()
{
JButton btn1=new JButton("1");
JButton btn2=new JButton("2");
JButton btn3=new JButton("3");
JButton btn4=new JButton("4");
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));
pn3.add(btn1);
pn3.add(btn2);
pn3.add(btn3);
pn3.add(btn4);
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 GridLayout());
fm.add(pn1);
fm.add(pn2);
fm.add(pn3);
}
public static void main(String[] args) {
new Ch115();
}
}
複製代碼
作者:
譚暐霖
時間:
2019-9-28 14:37
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();
}
}
複製代碼
作者:
高睿辰
時間:
2019-10-12 13:02
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("botton"+(i+1));
pn1=new JPanel();
pn1.setBorder(new EtchedBorder());
pn2=new JPanel();
pn2.setBorder(new TitledBorder("2"));
pn3=new JPanel();
pn3.setBorder(new TitledBorder(null,"3",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();
}
}
複製代碼
作者:
黃宥鈞
時間:
2019-10-12 13:47
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://seed.istak.org.tw/)
Powered by Discuz! 7.2