JPanel面板java
package jframe; import java.awt.Container; import java.awt.GridLayout; import javax.swing.*; public class jframe extends JFrame{ /** * */ private static final long serialVersionUID = 1L; public jframe(){ this.setTitle("test"); Container con = this.getContentPane(); JPanel p1 = new JPanel(new GridLayout(1,2,5,5)); //實例化兩個JPanel面板 JPanel p2 = new JPanel(new GridLayout(2,1,5,5)); p1.add(new JButton("1")); //加入按鈕 p1.add(new JButton("1")); p2.add(new JButton("2")); p2.add(new JButton("2")); con.setLayout(new GridLayout(2,1,10,10)); con.add(p1); con.add(p2); this.setVisible(true); this.setBounds(50, 50, 200, 200); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); //設置關閉方式,能夠選擇多種關閉玄子選項 } public static void main(String[] args) { new jframe(); } }
JScrollPane面板(帶滾動條的面板)編輯器
package jframe; import java.awt.Container; import javax.swing.*; public class jframe extends JFrame{ /** * */ private static final long serialVersionUID = 1L; public jframe(){ this.setTitle("test"); Container con = this.getContentPane(); JScrollPane jp = new JScrollPane(new JTextArea(50,20)); //實例化一個面板,加入一個文字編輯器 con.add(jp); this.setVisible(true); this.setBounds(50, 50, 200, 200); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); //設置關閉方式,能夠選擇多種關閉玄子選項 } public static void main(String[] args) { new jframe(); } }