import java.awt.BorderLayout;
import java.awt.HeadlessException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* @author jcuckoo
*
* 2014-7-31 下午2:41:33
*/
public class BorderLayoutTest extends JFrame {
public BorderLayoutTest() throws HeadlessException {
BorderLayout layout=new BorderLayout();
this.setLayout(layout);
this.add(new JButton("上部按钮"), BorderLayout.NORTH);
this.add(new JButton("右侧按钮"), BorderLayout.EAST);
this.add(new JButton("下部按钮"), BorderLayout.SOUTH);
this.add(new JButton("左侧按钮"), BorderLayout.WEST);
// this.add(new JButton("中间部分"), BorderLayout.CENTER);
JPanel panel=new JPanel(new BorderLayout());
panel.add(new JButton("上"), BorderLayout.NORTH);
panel.add(new JButton("右"), BorderLayout.EAST);
panel.add(new JButton("下"), BorderLayout.SOUTH);
panel.add(new JButton("左"), BorderLayout.WEST);
panel.add(new JButton("中"), BorderLayout.CENTER);
this.add(panel, BorderLayout.CENTER);
this.setSize(300, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
BorderLayoutTest test=new BorderLayoutTest();
}
}
//JTable-----------------------------------------
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
/**
* @author jcuckoo
*
* 2014-7-31 下午4:17:32
*/
public class JTableTest extends JFrame {
public JTableTest(){
this.setLayout(null);
String []columnNames={"ID","姓名","年龄"};
Object[][] rowData={{1,"张三",33},{2,"李四",24},{3,"王五",15}};
JTable table=new JTable(rowData,columnNames);
table.setBounds(0, 0, 300, 300);
JScrollPane pane=new JScrollPane(table);
pane.setBounds(0, 0, 300, 300);
this.add(pane);
this.setSize(300,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
JTableTest test=new JTableTest();
}
}