JAVA中Jtable的显示方式
想把获得的boolean类型输出时true/false显示Char类型男/女StuOpDbop=newStuOpDb();Listlist=op.getList();Ob...
想把获得的boolean类型输出时true/false显示Char类型男/女
StuOpDb op = new StuOpDb();
List list = op.getList();
Object[][] data = new Object[list.size()][6];
for (int i = 0; i < list.size(); i++) {
data[i][0] = ((Student) list.get(i)).getStuNum();
data[i][1] = ((Student) list.get(i)).getStuName();
data[i][2] = ((Student) list.get(i)).getStuSex();//加if判断也不行
data[i][3] = ((Student) list.get(i)).getMathScore();
data[i][4] = ((Student) list.get(i)).getCnScore();
data[i][5] = ((Student) list.get(i)).getEnScore();
}
table = new JTable();
table.setModel(new DefaultTableModel(data, new String[] { "学号",
"姓名", "性别", "数学成绩", "语文成绩", "英语成绩" }) {
Class[] columnTypes = new Class[] { Integer.class,
String.class, Boolean.class, Float.class,
Float.class, Float.class };
public Class getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}
public boolean isCellEditable(int row, int column) {// 指定某单元格是否可编辑
// if(column!=0)return true;
return false;
}
});
现在data[i][2] = ((Student) list.get(i)).getStuSex();获得的是boolean型
Class[] columnTypes = new Class[] { Integer.class,
String.class, Boolean.class, Float.class,//Boolean改成Char也不行
Float.class, Float.class }; 展开
StuOpDb op = new StuOpDb();
List list = op.getList();
Object[][] data = new Object[list.size()][6];
for (int i = 0; i < list.size(); i++) {
data[i][0] = ((Student) list.get(i)).getStuNum();
data[i][1] = ((Student) list.get(i)).getStuName();
data[i][2] = ((Student) list.get(i)).getStuSex();//加if判断也不行
data[i][3] = ((Student) list.get(i)).getMathScore();
data[i][4] = ((Student) list.get(i)).getCnScore();
data[i][5] = ((Student) list.get(i)).getEnScore();
}
table = new JTable();
table.setModel(new DefaultTableModel(data, new String[] { "学号",
"姓名", "性别", "数学成绩", "语文成绩", "英语成绩" }) {
Class[] columnTypes = new Class[] { Integer.class,
String.class, Boolean.class, Float.class,
Float.class, Float.class };
public Class getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}
public boolean isCellEditable(int row, int column) {// 指定某单元格是否可编辑
// if(column!=0)return true;
return false;
}
});
现在data[i][2] = ((Student) list.get(i)).getStuSex();获得的是boolean型
Class[] columnTypes = new Class[] { Integer.class,
String.class, Boolean.class, Float.class,//Boolean改成Char也不行
Float.class, Float.class }; 展开
2个回答
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询