表格(JTABLE)中的标题可以更改,我想把它设置成为无法更改表格中的标题!
/*** * AdminFrame.java * * Created on DATE, TIME */
package com.nk.frame;
import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; import java.awt.Font; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; import java.util.List; import java.util.Map;
import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextField;
import com.nk.bean.ProjectInfo; import com.nk.bean.UserInfo; import com.nk.service.IProjectService; import com.nk.service.IUserService; import com.nk.service.impl.ProjectServiceImpl; import com.nk.service.impl.UserServiceImpl;
/*** * * @author USER */ public class AdminFrame extends javax.swing.JFrame {
private IUserService uerUserService = new UserServiceImpl();
private IProjectService projectService = new ProjectServiceImpl();
private List<UserInfo> list;
private List<ProjectInfo> list2;
private JFrame frame;
private javax.swing.JTabbedPane jTabbedPane;
private javax.swing.JPanel titleJPanel;
private javax.swing.JPanel userPanel;
private javax.swing.JPanel projectPanel;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton12;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JTable jTable1;
private javax.swing.JTable jTable2;
private javax.swing.JTextField jTextField1;
private Object table[][];
private Object jtTable[][];
private Object jtTableData[][];
private String searchTypeString = "按姓名查询";
private javax.swing.JPanel tongjiJPanel;
private JTextField jtField1;
private JTextField jtField2;
private JTextField jtField3;
private JTextField jtField4;
private JTextField jtField5;
private JTextField jtField6;
private JTextField jtField7;
private JTextField jtField8;
private JTextField jtField9;
private JComboBox jc;
private JComboBox jc1;
private JComboBox jc2;
int pageSize = 10;
private Integer curPage = 0;
// End of variables declaration//GEN-END:variables
/** Creates new form AdminFrame */
public AdminFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
frame = new JFrame();
frame.setTitle("土肥管理系统");
frame.getContentPane().setLayout(new BorderLayout());
frame.setBounds(0, 0, 1024, 560);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
titleJPanel = new JPanel();
jTabbedPane = new JTabbedPane();
// 初始化标题
initTilePanel(titleJPanel);
jTabbedPane.setTabPlacement(JTabbedPane.LEFT);
userPanel = getUserInfoPanel();
jTabbedPane.addTab("用户列表", null, userPanel, null);
userPanel.setLayout(null);
tongjiJPanel = getTongjiPanel();
jTabbedPane.addTab("信息统计", null, tongjiJPanel, null);
tongjiJPanel.setLayout(null);
frame.getContentPane().add(titleJPanel, BorderLayout.NORTH);
frame.getContentPane().add(jTabbedPane, BorderLayout.CENTER);
}// </editor-fold>
// GEN-END:initComponents
/**
* 初始化用户信息列表
*/
private JPanel getUserInfoPanel() {
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jComboBox1 = new javax.swing.JComboBox();
jTextField1 = new javax.swing.JTextField();
jTable1 = new javax.swing.JTable();
jTable2 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
// 上一页
jButton8 = new javax.swing.JButton();
// 下一页
jButton9 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
jButton12 = new javax.swing.JButton();
userPanel = new JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
userPanel.add(jButton3);
jButton3.setText("\u67e5\u8be2");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton3.setBounds(280, 10, 60, 24);
userPanel.add(jButton4);
jButton4.setText("\u5220\u9664");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt, userPanel);
}
});
jButton4.setBounds(350, 10, 60, 24);
userPanel.add(jButton5);
jButton5.setText("\u6253\u5370");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton5.setBounds(420, 10, 60, 24);
userPanel.add(jComboBox1);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
"按姓名查询", "按用户名查询", "按地点查询", "按时间查询" }));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
}
});
jComboBox1.setBounds(10, 10, 120, 24);
userPanel.add(jTextField1);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jTextField1.setBounds(150, 10, 120, 24);
final List<UserInfo> userList = uerUserService.findAllUserList();
userPanel.add(jButton8);
jButton8.setText("上一页");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
// 上一页
preActionPerformed(evt, userList);
}
});
jButton8.setBounds(360, 300, 120, 24);
userPanel.add(jButton9);
jButton9.setText("下一页");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
// 上一页
nextActionPerformed(evt, userList);
}
});
jButton9.setBounds(480, 300, 120, 24);
// 初始化表格
initUserInfo(userPanel);
return userPanel;
}
// 上一页
protected void preActionPerformed(ActionEvent evt, List<UserInfo> userList) {
// TODO Auto-generated method stub
if (curPage > 0) {
curPage = curPage - 1;
}
// 初始化表格
initUserInfo(userPanel);
}
// 下一页
protected void nextActionPerformed(ActionEvent evt, List<UserInfo> userList) {
// TODO Auto-generated method stub
int num = userList.size() / pageSize;
if (curPage < num) {
curPage = curPage + 1;
// 初始化表格
initUserInfo(userPanel);
}
}
/**
* 初始化统计信息的内容
*
* @return
*/
private JPanel getTongjiPanel() {
tongjiJPanel = new JPanel();
jtField1 = new JTextField();
jtField2 = new JTextField();
jtField3 = new JTextField();
jtField4 = new JTextField();
jtField5 = new JTextField();
jtField6 = new JTextField();
jtField8 = new JTextField();
jtField7 = new JTextField();
jtField9 = new JTextField();
jc = new JComboBox();
jc1 = new JComboBox();
jc2 = new JComboBox();
JLabel tJLabe9 = new JLabel();
tJLabe9.setText("统计参数");
tJLabe9.setBounds(0, 0, 300, 35);
tJLabe9.setFont(new Font("微软雅黑", Font.BOLD, 20));
tongjiJPanel.add(tJLabe9);
JLabel tJLabe11 = new JLabel();
tJLabe11.setText("统计结果");
tJLabe11.setBounds(0, 260, 300, 35);
tJLabe11.setFont(new Font("微软雅黑", Font.BOLD, 20));
tongjiJPanel.add(tJLabe11);
JLabel tJLabel1 = new JLabel();
tJLabel1.setText("开 始 时 间:");
tJLabel1.setBounds(3, 0, 150, 100);
tongjiJPanel.add(tJLabel1);
jtField1.setBounds(125, 35, 95, 25);
tongjiJPanel.add(jtField1);
JLabel tJLabel2 = new JLabel();
tJLabel2.setText("结 束 时 间:");
tJLabel2.setBounds(450, 10, 150, 100);
tongjiJPanel.add(tJLabel2);
jtField2.setBounds(555, 40, 95, 25);
tongjiJPanel.add(jtField2);
JLabel tJLabel3 = new JLabel();
tJLabel3.setText("小麦最低产量:");
tJLabel3.setBounds(3, 39, 150, 100);
tongjiJPanel.add(tJLabel3);
jtField3.setBounds(125, 80, 95, 25);
tongjiJPanel.add(jtField3);
JLabel tJLabel4 = new JLabel();
tJLabel4.setText("小麦最高产量");
tJLabel4.setBounds(450, 40, 150, 100);
tongjiJPanel.add(tJLabel4);
jtField4.setBounds(555, 75, 95, 25);
tongjiJPanel.add(jtField4);
JLabel tJLabel5 = new JLabel();
tJLabel5.setText("玉米最低产量:");
tJLabel5.setBounds(3, 96, 150, 60);
tongjiJPanel.add(tJLabel5);
jtField5.setBounds(125, 115, 95, 25);
tongjiJPanel.add(jtField5);
JLabel tJLabel6 = new JLabel();
tJLabel6.setText("玉米最高产量:");
tJLabel6.setBounds(450, 70, 150, 100);
tongjiJPanel.add(tJLabel6);
jtField6.setBounds(555, 108, 95, 25);
tongjiJPanel.add(jtField6);
JLabel tJLabel7 = new JLabel();
tJLabel7.setText("地 区(请填写省份):");
tJLabel7.setBounds(3, 118, 150, 100);
tongjiJPanel.add(tJLabel7);
jtField7.setBounds(125, 150, 95, 25);
tongjiJPanel.add(jtField7);
/*
* jc.setBounds(125, 150, 95,25); jc.setModel(new
* javax.swing.DefaultComboBoxModel(new String[] { "安徽", "北京", "福建",
* "甘肃", "广东", "广西", "贵州", "海南", "河北", "河南", "黑龙江", "湖北", "湖南", "吉林",
* "江苏", "江西", "辽宁", "内蒙古", "宁夏", "青海", "山东", "山西", "陕西", "上海", "四川",
* "天津", "西藏", " 新疆", "云南", "浙江", "重庆" })); jc1.setBounds(305, 150,
* 95,25); jc1.setModel(new javax.swing.DefaultComboBoxModel(new
* String[] { "安徽", "北京", "福建", "甘肃", "广东", "广西", "贵州", "海南", "河北",
* "河南", "黑龙江", "湖北", "湖南", "吉林", "江苏", "江西", "辽宁", "内蒙古", "宁夏", "青海",
* "山东", "山西", "陕西", "上海", "四川", "天津", "西藏", " 新疆", "云南", "浙江", "重庆"}));
* jc2.setBounds(500, 150, 95,25); jc2.setModel(new
* javax.swing.DefaultComboBoxModel(new String[] { "安徽", "北京", "福建",
* "甘肃", "广东", "广西", "贵州", "海南", "河北", "河南", "黑龙江", "湖北", "湖南", "吉林",
* "江苏", "江西", "辽宁", "内蒙古", "宁夏", "青海", "山东", "山西", "陕西", "上海", "四川",
* "天津", "西藏", " 新疆", "云南", "浙江", "重庆"}));
*
*
* tongjiJPanel.add(jc); tongjiJPanel.add(jc1); tongjiJPanel.add(jc2);
*/
JLabel tJLabel8 = new JLabel();
tJLabel8.setText("实施起始面积:");
tJLabel8.setBounds(3, 155, 150, 100);
tongjiJPanel.add(tJLabel8);
jtField8.setBounds(125, 188, 95, 25);
tongjiJPanel.add(jtField8);
JLabel tJLabel9 = new JLabel();
tJLabel9.setText("实施结束面积:");
tJLabel9.setBounds(450, 155, 150, 100);
tongjiJPanel.add(tJLabel9);
jtField9.setBounds(555, 188, 95, 25);
tongjiJPanel.add(jtField9);
JButton jButton1 = new JButton();
jButton1.setText("开始统计");
jButton1.setBounds(400, 230, 100, 30);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt, tongjiJPanel);
}
});
tongjiJPanel.add(jButton1);
JButton jButton2 = new JButton();
jButton2.setText("打 印");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton2.setBounds(555, 230, 100, 30);
tongjiJPanel.add(jButton2);
// 单独处理表格数据显示部分
initProjectInfo(tongjiJPanel);
return tongjiJPanel;
}
// 开始统计事件
protected void jButton1ActionPerformed(ActionEvent evt, JPanel panel) {
String startTimeString = jtField1.getText();
String endTimeString = jtField2.getText();
String xmminYieldString = jtField3.getText();
String xmmaxYieldString = jtField4.getText();
String ymminYieldString = jtField5.getText();
String ymmaxYieldString = jtField6.getText();
String proviceString = jtField7.getText();
String infoStartString = jtField8.getText();
String endStartString = jtField9.getText();
List<ProjectInfo> pList = projectService.findProject(startTimeString,
endTimeString, proviceString, xmminYieldString,
xmmaxYieldString, ymminYieldString, ymmaxYieldString,
infoStartString, endStartString);
// TODO Auto-generated method stub
initProjectInfoSearch(pList, panel);
}
/**
* 初始化标题
*
* @return
*/
private JPanel initTilePanel(JPanel titleJPanel) {
jLabel1 = new javax.swing.JLabel();
titleJPanel.add(jLabel1);
jLabel1.setFont(new java.awt.Font("微软雅黑", 0, 18));
jLabel1.setText("\u6b22\u8fce\u8fdb\u5165\u571f\u80a5\u7ba1\u7406\u7cfb\u7edf");
jLabel1.setBorder(javax.swing.BorderFactory
.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
jLabel1.setBounds(120, 120, 240, 30);
return titleJPanel;
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* 获取当前搜索的条件
*/
public void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
searchTypeString = jComboBox1.getSelectedItem().toString();
}
@SuppressWarnings({ "username", "realname", "regtime", "province" })
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
String realname = null;
String username = null;
String regtime = null;
String province = null;
final String search = jTextField1.getText();
if ("打印".equals(searchTypeString)) {
if (username.equals("") && realname.equals("")
&& regtime.equals(" ") && province.equals(" ")) {
list = uerUserService.findUserInfo(realname, username, regtime,
province);
// 根据输入值去数据库里面查找数据
UserInfo userInfo = uerUserService.selectByUsername(search);
// 刷新显示数据的表格
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] { { userInfo.getId(),
userInfo.getUsername(), userInfo.getRealname(),
userInfo.getPasswd(), userInfo.getCity(),
userInfo.getPhone(), userInfo.getCity(),
userInfo.getRegtime() } },
new String[] { "id", "姓名", "用户名", "密码", "项目个数", "手机",
"所在地区", "注册时间" }));
}
// list = uerUserService.findUserInfo(realname, username,
// regtime,province);
if (list.size() > 0) {
JOptionPane.showMessageDialog(null, "打印成功");
} else {
JOptionPane.showMessageDialog(null, "用户不存在");
}
} else {
JOptionPane.showMessageDialog(null, "无法连接打印机");
}
}
/**
* 绑定的删除功能
*
* @param evt
*/
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt,
JPanel userPanel) {
Integer id = 0;
JOptionPane.showMessageDialog(null, "确定删除?", "土肥管理系统",
JOptionPane.ERROR_MESSAGE);
// 获取选中的行
id = Integer.valueOf(table[jTable1.getSelectedRow()][0].toString());
// 删除选中的行数据,(物理性删除)
uerUserService.delectUserList(id);
// 刷新显示数据的表格
initUserInfo(userPanel);
}
/**
* 执行查询操作
*
* @param evt
*/
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
/**
* 获取到的查询输入值
*/
final String search = jTextField1.getText();
List<UserInfo> userInfoList = null;
if ("按姓名查询".equals(searchTypeString)) {
// 根据输入值去数据库里面查找数据
userInfoList = uerUserService
.findUserInfo(search, null, null, null);
} else if ("按用户名查询".equals(searchTypeString)) {
// 根据输入值去数据库里面查找数据
userInfoList = uerUserService
.findUserInfo(null, search, null, null);
} else if ("按地点查询".equals(searchTypeString)) {
// 根据输入值去数据库里面查找数据
userInfoList = uerUserService
.findUserInfo(null, null, null, search);
} else if ("按时间查询".equals(searchTypeString)) {
// 根据输入值去数据库里面查找数据
userInfoList = uerUserService
.findUserInfo(null, null, search, null);
}
if (userInfoList != null && userInfoList.size() > 0) {
initUserInfoSearch(userInfoList);
} else {
JOptionPane.showMessageDialog(null, "查询无数据,请检查输入条件", "土肥管理系统",
JOptionPane.ERROR_MESSAGE);
initUserInfoSearch(userInfoList);
}
}
/**
*
* 初始化用户表格数据
*/
@SuppressWarnings("unchecked")
private void initUserInfo(JPanel userPanel) {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("startLine", curPage * pageSize);
map.put("pageSize", pageSize);
final List<UserInfo> userList = uerUserService.findAll(map);
table = new Object[userList.size() + 1][8];
table[0][0] = "id";
table[0][1] = "姓名";
table[0][2] = "用户名";
table[0][3] = "密码";
table[0][4] = "项目个数";
table[0][5] = "手机";
table[0][6] = "所在地区";
table[0][7] = "注册时间";
int i = 1;
if (userList != null && userList.size() > 0) {
for (UserInfo user : userList) {
table[i][0] = user.getId();
table[i][1] = user.getUsername();
table[i][2] = user.getRealname();
table[i][3] = user.getPasswd();
table[i][4] = user.getItems();
table[i][5] = user.getPhone();
table[i][6] = user.getCity();
table[i][7] = user.getRegtime();
i++;
}
}
userPanel.add(jTable1);
jTable1.setModel(new javax.swing.table.DefaultTableModel(table,
new String[] { "id", "姓名", "用户名", "密码", "项目个数", "手机", "所在地区",
"注册时间" }));
jTable1.setFont(new Font("微软雅黑", Font.BOLD, 14));
jTable1.setBounds(10, 60, 720, 400);
}
/**
*
* 初始化统计表格数据
*/
@SuppressWarnings("unused")
private void initProjectInfo(JPanel projectPanel) {
List<ProjectInfo> projectlist = projectService.findAllproject();
jtTableData = new Object[projectlist.size() + 1][5];
jtTableData[0][0] = "项目名称";
jtTableData[0][1] = "面 积";
jtTableData[0][2] = "地理位置";
jtTableData[0][3] = "小麦产量";
jtTableData[0][4] = "玉米产量";
// jtTableData[0][5] = "操 作";
int i = 1;
if (projectlist != null && projectlist.size() > 0) {
for (ProjectInfo project : projectlist) {
jtTableData[i][0] = project.getProjectname();
jtTableData[i][1] = project.getArea();
jtTableData[i][2] = project.getProvince();
jtTableData[i][3] = project.getWheat();
jtTableData[i][4] = project.getCorn();
i++;
}
}
projectPanel.add(jTable2);
jTable2.setModel(new javax.swing.table.DefaultTableModel(jtTableData,
new String[] { "项目名称", "面 积", "小麦产量", "小麦产量", "玉米产量" }));
jTable2.setFont(new Font("微软雅黑", Font.BOLD, 14));
jTable2.setBounds(3, 295, 720, 400);
Map<String, Integer> map1 = new HashMap<String, Integer>();
map1.put("startLine", curPage * pageSize);
map1.put("pageSize", pageSize);
final List<ProjectInfo> projectList = projectService.findAllproject();
projectPanel.add(jButton11);
jButton11.setText("上一页");
jButton11.setBounds(750, 350, 120, 24);
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
// 上一页
lastActionPerformed(evt, projectList);
}
});
projectPanel.add(jButton12);
jButton12.setText("下一页");
jButton12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
// xia一页
nexttimeActionPerformed(evt, projectList);
}
});
jButton12.setBounds(750, 400, 120, 24);
}
// 上一页
protected void lastActionPerformed(ActionEvent evt,
List<ProjectInfo> projectList) {
// TODO Auto-generated method stub
if (curPage > 0) {
curPage = curPage - 1;
}
// 初始化表格
initProjectInfo(projectPanel);
}
// 下一页
protected void nexttimeActionPerformed(ActionEvent evt,
List<ProjectInfo> projectList) {
// TODO Auto-generated method stub
int num = projectList.size() / pageSize;
if (curPage < num) {
curPage = curPage + 1;
// 初始化表格
initProjectInfo(projectPanel);
}
}
/**
*
* 初始化查询表格数据
*/
@SuppressWarnings("unused")
private void initUserInfoSearch(List<UserInfo> userList) {
table = new Object[userList.size() + 1][8];
table[0][0] = "id";
table[0][1] = "姓名";
table[0][2] = "用户名";
table[0][3] = "密码";
table[0][4] = "项目个数";
table[0][5] = "手机";
table[0][6] = "所在地区";
table[0][7] = "注册时间";
int i = 1;
if (userList != null && userList.size() > 0) {
if (userList != null && userList.size() > 0) {
for (UserInfo user : userList) {
table[i][0] = user.getId();
table[i][1] = user.getUsername();
table[i][2] = user.getRealname();
table[i][3] = user.getPasswd();
table[i][4] = user.getItems();
table[i][5] = user.getPhone();
table[i][6] = user.getCity();
table[i][7] = user.getRegtime();
i++;
}
}
} else {
table = new Object[userList.size()][8];
}
userPanel.add(jTable1);
jTable1.setModel(new javax.swing.table.DefaultTableModel(table,
new String[] { "id", "姓名", "用户名", "密码", "项目个数", "手机", "所在地区",
"注册时间" }));
jTable1.setFont(new Font("微软雅黑", Font.BOLD, 14));
jTable1.setBounds(10, 60, 720, 400);
}
/**
*
* 初始化统计表格数据
*/
@SuppressWarnings("unused")
private void initProjectInfoSearch(List<ProjectInfo> projectlist,
JPanel projectPanel) {
jtTableData = new Object[projectlist.size() + 1][5];
jtTableData[0][0] = "项目名称";
jtTableData[0][1] = "面 积";
jtTableData[0][2] = "地理位置";
jtTableData[0][3] = "小麦产量";
jtTableData[0][4] = "玉米产量";
// jtTableData[0][5] = "操 作";
int i = 1;
if (projectlist != null && projectlist.size() > 0) {
for (ProjectInfo project : projectlist) {
jtTableData[i][0] = project.getProjectname();
jtTableData[i][1] = project.getArea();
jtTableData[i][2] = project.getProvince();
jtTableData[i][3] = project.getWheat();
jtTableData[i][4] = project.getCorn();
i++;
}
}
projectPanel.add(jTable2);
jTable2.setModel(new javax.swing.table.DefaultTableModel(jtTableData,
new String[] { "项目名称", "面 积", "小麦产量", "小麦产量", "玉米产量" }));
jTable2.setFont(new Font("微软雅黑", Font.BOLD, 14));
jTable2.setBounds(3, 295, 720, 400);
}
/**
* @param args
* the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
AdminFrame window = new AdminFrame();
window.frame.setVisible(true);
}
});
}
/**
*
* @return
*/
public List<UserInfo> getList() {
return list;
}
public void setList(List<UserInfo> list) {
this.list = list;
}
}
这一大片代码, 看的头晕. 不知道你问的是不是这个意思, Swing里面, 要让组件不可编辑: comp.setEnable(false)就可以了. 对于表头:
table.getTableHeader().setEnabled(false);
Swing的复杂组件通常都是基于一些简单组件的, 找到放置标题的组件, comp.setEnabled(flase)就可以了. ######直接用comp.setEnable(false)是对整张表的控制!下面那条对我很有帮助,谢谢!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。