Java Swing 的一点小问题!
青稞梅子酒 2011-02-21 09:37:39
import java.awt.*;
import javax.swing.*;
public class list {
public static void main(String args[]) {
// Container container = f.getContentPane();
// 获得与JFrame关联的ContentPane,ContentPane的默认布局管理器是BorderLayout;
// final Object rowData[][] = {
// { "1", "one", "I" },
// { "2", "two", "II" },
// { "3", "three", "III" }};
// final String columnNames[] = { "姓名", "性别", "年龄","职务" };
final JTable Table = new JTable(20, 6);// 创建表格;
Table.setRowHeight(25);// 设置表格的行高;
JScrollPane scrollPane = new JScrollPane(Table);// 创建滚动条
JFrame f = new JFrame("员工表");// 创建JFrame对象;
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 点关闭,停止进程
JPanel NorthPanel = new JPanel();
// 创建北面的JPanel对象;
JLabel label = new JLabel("员工信息表");
Font font = new Font("宋体", 10, 20);// 新建字体;
label.setFont(font);// 应用字体;
NorthPanel.add(label);// 把标签添加到NorthPanel中;
JPanel SouthPanel = new JPanel();
Button button1 = new Button("增加");
Button button2 = new Button("删除");
Button button3 = new Button("查找");
Button button4 = new Button("修改");
SouthPanel.add(button1);
SouthPanel.add(button2);
SouthPanel.add(button3);
SouthPanel.add(button4);
f.add(SouthPanel, BorderLayout.SOUTH);
f.add(NorthPanel, BorderLayout.NORTH);// 加入标签”员工信息表“;
f.add(scrollPane, BorderLayout.CENTER);// 把NorthPanel添加到container中;
// f.setResizable(false);//定义窗口是否可调整大小
f.setSize(700, 550);// 定义JFrame窗口大小;
f.setLocationRelativeTo(f);// 窗口居中显示;
f.setVisible(true);// 显示窗口
}
}
有两个问题:
1、想让表格只占窗口的一半(窗口目前的大小不变),就是设置表格的大小!
2、设置Button的大小,我用setSize方法设置不管用啊!
高手来帮帮忙!多谢啦!