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 ...
随机推荐
- 使用jsp+javabean完成用户登陆功能
User.java package com.po; public class User implements java.io.Serializable { private String usernam ...
- MongoDB命令语法小用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using MongoDB; ...
- CSS3 3D发光切换按钮
在线演示 本地下载
- EXP-00008:遇到ORACLE错误904问题
案例情景--在一次Oracle 数据库导出时: C:\Documents and Settings\Administrator>exp lsxy/lsxy@lsxy_db file=E:\lsx ...
- 《Inode与Block重要知识总结核心讲解》【转】
本文转载自:https://blog.csdn.net/BlackEnn/article/details/50787092 1.查看/dev/sda1下磁盘分区的block大小: 2.查看单个inod ...
- 设置 IntelliJ IDEA 主题和字体的方法
1 前言 在博文「IntelliJ IDEA 之 HelloWorld 项目创建及相关配置文件介绍」中,我们已经用 IntelliJ IDEA 创建了第一个 Java 项目 HelloWorld,如下 ...
- 基于netty的异步http请求
package com.pt.utils; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; im ...
- How to use Jenkins
一.关键点 1.how to start the build server? do i need to start some app to do this? I don't believe so... ...
- Spark基本概念快速入门
Spark集群 一组计算机的集合,每个计算机节点作为独立的计算资源,又可以虚拟出多个具备计算能力的虚拟机,这些虚拟机是集群中的计算单元.Spark的核心模块专注于调度和管理虚拟机之上分布式计算任务 ...
- ActiveMQ消费者接收消息的过程
[http://manzhizhen.iteye.com/blog/2094130] org.apache.activemq.ActiveMQMessageConsumer同步接收