Jtable实现
package database;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;
public class Empmodel extends AbstractTableModel{
Vector<String> colums;
Vector<Vector> rows;
//写一个方法,用于查询需要的显示的人事信息
public void query(){
this.colums=new Vector<String>();
this.colums.add("员工号");
this.colums.add("姓名");
this.colums.add("性别");
this.colums.add("职位");
rows=new Vector<Vector>();
for (int i=1;i<=10;i++){
Vector<String> tem=new Vector<String>();
tem.add(i+"");
tem.add("luozt"+i+"");
tem.add("男");
tem.add("QA");
rows.add(tem);
}
}
@Override
public String getColumnName(int column) {
// TODO Auto-generated method stub
return this.colums.get(column).toString();
}
@Override
public int getRowCount() {
// TODO Auto-generated method stub
return this.rows.size();
}
@Override
public int getColumnCount() {
// TODO Auto-generated method stub
return this.colums.size();
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
// TODO Auto-generated method stub
return ((Vector)rows.get(rowIndex)).get(columnIndex);
}
}
//调用上面的JTable
package UI;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import database.Empmodel;
import tools.mytool;
public class EmpInfo extends JPanel{
public static void main(String[] args) {
// TODO Auto-generated method stub
EmpInfo emp=new EmpInfo();
}
JPanel jp1,jp2,jp3,jp4,jp5;
JLabel jp1_label,jp3_label;
JTextField jp1_jtf;
JButton jp1_button,jp4_button1,jp4_button2,jp4_button3,jp4_button4;
JTable jtb;
JScrollPane jsp;
public EmpInfo(){
jp1=new JPanel(new FlowLayout(FlowLayout.CENTER));
jp1_label=new JLabel("请输入姓名(员工或职位)");
jp1_label.setFont(mytool.f2);
jp1_jtf=new JTextField(20);
jp1_button=new JButton("查询");
jp1_button.setFont(mytool.f3);
jp1.add(jp1_label);
jp1.add(jp1_jtf);
jp1.add(jp1_button);
//center
Empmodel emp=new Empmodel();
emp.query();
jtb=new JTable(emp);
jp2=new JPanel(new BorderLayout());
//jtb 要放在JScrollPane里否则表头看不见
jsp=new JScrollPane(jtb);
jp2.add(jsp);
jp2.setBorder(BorderFactory.createTitledBorder("人事信息"));
jp3=new JPanel(new FlowLayout(FlowLayout.LEFT));
jp3_label=new JLabel("总记录是10条");
jp3_label.setFont(mytool.f3);
jp3.add(jp3_label);
jp4=new JPanel(new FlowLayout(FlowLayout.RIGHT));
jp4_button1=new JButton("详细信息");
jp4_button1.setFont(mytool.f3);
jp4_button2=new JButton("修改");
jp4_button2.setFont(mytool.f3);
jp4_button3=new JButton("添加");
jp4_button3.setFont(mytool.f3);
jp4_button4=new JButton("删除");
jp4_button4.setFont(mytool.f3);
jp4.add(jp4_button1);
jp4.add(jp4_button2);
jp4.add(jp4_button3);
jp4.add(jp4_button4);
jp5=new JPanel(new BorderLayout());
jp5.add(jp3,"West");
jp5.add(jp4,"East");
this.setLayout(new BorderLayout());
this.add(jp1,"North");
this.add(jp2,"Center");
this.add(jp5,"South");
//this.setBackground(Color.pink);
this.setVisible(true);
}
}
Jtable实现的更多相关文章
- swing中JTable的使用方法
public static void main(String[] args) { Student s1 = new Student("张三", "001", 0 ...
- Jtable 表格按多列排序(支持中文汉字排序)
这两天公司让做一个Jtable表格的排序,首先按A列排序,在A列相等时按B列排序,B列相等时按C列排序,ABC三列可以任意指定,最多分三列,这样的一个需求.由于我是大神,所以必须做了出来.ok,不自恋 ...
- Java — JTree and JTable以及sqlServer的两种连接
使用JTree的步骤: 暂时只能创建一个头结点,创建一个树的结点作为头结点(其子结点也是相同的创建方法):DefaultMutableTreeNode headNode = new DefaultMu ...
- ABP JTable如何手动刷新子表数据
function getSubMaster() { _$masterTable.find('.jtable-child-table-container').jtable('reload'); }
- jtable插件api
官网2016-03-15 事例图: 一.客户端配置 1. paging boolean default:false 配置是否分页,果断改为true. 2. pageList string defaul ...
- ASP.NET ZERO 学习 JTable的使用子表闭合功能
双击子表自动判定开闭功能 //CHILD TABLE DEFINITION FOR "PHONE NUMBERS" Phones: { title: '', width: '5%' ...
- ASP.NET ZERO 学习 JTable的ChildTable用法
效果图: Jtable的子表用法: _$masterTable.jtable({ title: app.localize('PharmacyInventory'), openChildAsAccord ...
- jtable更新数据
static JTable table; public void refrushTableData() { String[] columnNames = { " }; String[][] ...
- 实现Java JTable的应用案例
代码如下 import Java.awt.Component; import java.awt.Dimension; import java.awt.FontMetrics; import javax ...
- JavaSE GUI显示列表 JTable的刷新 重新加载新的数据
JTable在显示所有数据之后,假如需要搜索某个名字,则会获取新的列表数据. 假设datas是JTable的数据,定义为: private Vector<Vector> datas = n ...
随机推荐
- DD DT DL标签
我们平时常用的是< ul>< li>标签,不过dd.dt标签也蛮不错,特别是发布程序的时候功能模块列表什么的可以使用它来排版. < dl>< /dl>& ...
- Kafka Confluent
今天我们要讲的大数据公司叫作Confluent,这个公司是前LinkedIn员工出来后联合创办的,而创业的基础是一款叫作Apache Kafka的开源软件. Confluen联合创始人Jun Rao即 ...
- Zuul
一.zuul是什么 zuul 是netflix开源的一个API Gateway 服务器, 本质上是一个web servlet应用. Zuul 在云平台上提供动态路由,监控,弹性,安全等边缘服务的框架. ...
- 查看oracle当前连接数和进程数
查询数据库当前进程的连接数: select count(*) from v$process; 查看数据库当前会话的连接数: select count(*) from v$session; 查看数据库的 ...
- Mysql 主从复制搭建
Mysql 主重复制搭建 Linux版本:Linux Centos 6.4 32位 Mysql版本:Mysql-5.6.38-linux-glibc2.12-i686 Mysql安装:Mysql安装教 ...
- SpringBoot Maven打包项目JAR/WAR
安装Maven 1. 登录 http://maven.apache.org/download.cgi 2. 下载 maven 压缩包 3. 解压apache-maven-3.6.0-bin.tar.g ...
- 2018-02-11 发布 spring 自定义注解(annotation)与 aop获取注解
知识点: Java自定义注解.spring aop @aspect的使用 首先我们先介绍Java自定义注解. 在开发过程中,我们实现接口的时候,会出现@Override,有时还会提示写@Suppres ...
- 关于CDN
DNS域名解析过程 DNS即Domain Name System,是域名解析服务的意思.它在互联网的作用是:把域名转换成为网络可以识别的ip地址.人们习惯记忆域名,但机器间互相只认IP地址,域名与IP ...
- 一个简单的Javascript闭包示例
//=====用闭包实现函数的Curry化===== //数字求和函数的函数生成器 function addGenerator( num ){ //返回一个简单的匿名函数,求两个数的和,其中第一个数字 ...
- Google Chrome 未响应。是否立即重新启动?
不当的退出会造成 Google Chrome 无法启动.出现“Google Chrome 未响应.是否立即重新启动?”的错误.要解决这个问题: 1.同时按住Windows旗帜键 + R键,调 ...