Java Swing 的一点小问题!

青稞梅子酒 青稞梅子酒 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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方法设置不管用啊!

高手来帮帮忙!多谢啦!
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
青稞梅子酒
J2ME 13,096 成员 26,491 内容