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实现的更多相关文章

  1. swing中JTable的使用方法

    public static void main(String[] args) { Student s1 = new Student("张三", "001", 0 ...

  2. Jtable 表格按多列排序(支持中文汉字排序)

    这两天公司让做一个Jtable表格的排序,首先按A列排序,在A列相等时按B列排序,B列相等时按C列排序,ABC三列可以任意指定,最多分三列,这样的一个需求.由于我是大神,所以必须做了出来.ok,不自恋 ...

  3. Java — JTree and JTable以及sqlServer的两种连接

    使用JTree的步骤: 暂时只能创建一个头结点,创建一个树的结点作为头结点(其子结点也是相同的创建方法):DefaultMutableTreeNode headNode = new DefaultMu ...

  4. ABP JTable如何手动刷新子表数据

    function getSubMaster() { _$masterTable.find('.jtable-child-table-container').jtable('reload'); }

  5. jtable插件api

    官网2016-03-15 事例图: 一.客户端配置 1. paging boolean default:false 配置是否分页,果断改为true. 2. pageList string defaul ...

  6. ASP.NET ZERO 学习 JTable的使用子表闭合功能

    双击子表自动判定开闭功能 //CHILD TABLE DEFINITION FOR "PHONE NUMBERS" Phones: { title: '', width: '5%' ...

  7. ASP.NET ZERO 学习 JTable的ChildTable用法

    效果图: Jtable的子表用法: _$masterTable.jtable({ title: app.localize('PharmacyInventory'), openChildAsAccord ...

  8. jtable更新数据

    static JTable table; public void refrushTableData() { String[] columnNames = { " }; String[][] ...

  9. 实现Java JTable的应用案例

    代码如下 import Java.awt.Component; import java.awt.Dimension; import java.awt.FontMetrics; import javax ...

  10. JavaSE GUI显示列表 JTable的刷新 重新加载新的数据

    JTable在显示所有数据之后,假如需要搜索某个名字,则会获取新的列表数据. 假设datas是JTable的数据,定义为: private Vector<Vector> datas = n ...

随机推荐

  1. webAPI支持跨域

    问题描述: 添加引用:右键项目→添加nuget包 在:App_Start/WebApiConfig.Register中添加如下一句话 //跨域配置 config.EnableCors(new Enab ...

  2. ubuntu里设置从串口登录

    1) Create a file called /etc/init/ttyS0.conf containing the following: # ttySAC0 - getty # # This se ...

  3. linux 音频驱动

    转:https://wenku.baidu.com/view/7394e16d7e21af45b307a8dc.html?pn=51 linux_sound_alsa_ALSA体系SOC子系统中数据流 ...

  4. ubuntu关闭631(cups)端口

    在ubuntu17.04环境下使用nmap扫描自己机器,发现631端口处于开启状态,将其输入到浏览器,可以看出是网络打印机的服务: 这个端口开着总是那么的刺眼,(5.12全球爆发的勒索病毒让人不寒而栗 ...

  5. Centos7 关闭Ipv6

  6. 出现GC overhead limit exceeded 的解决方案

    当我在使用MyEclispe IDE创建Maven项目的时候出现  "An internal error occurred during: “Build Project”. GC overh ...

  7. 基于canvas与原生JS的H5动画引擎

    前一段时间项目组里有一些H5动画的需求,由于没有专业的前端人员,便交由我这个做后台的研究相关的H5动画技术. 通过初步调研,H5动画的实现大概有以下几种方式: 1.基于css实现 这种方式比较简单易学 ...

  8. HDU 5925 离散化

    东北赛的一道二等奖题 当时学长想了一个dfs的解法并且通过了 那时自己也有一个bfs的解法没有拿出来 一直没有机会和时ji间xing来验证对错 昨天和队友谈离散化的时候想到了 于是用当时的思路做了一下 ...

  9. Python之单例模式总结

    一.单例模式 a.单例模式分为四种:文件,类,基于__new__方法实现单例模式,基于metaclass方式实现 b.类实现如下: class Sigletion(objects): import t ...

  10. Ceilometer Polling Performance Improvement

    Ceilometer的数据采集agent会定期对nova/keystone/neutron/cinder等服务调用其API的获取信息,默认是20秒一次, # Polling interval for ...