码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA-setDataVector范例

时间:2016-06-02 00:49:42      阅读:723      评论:0      收藏:0      [点我收藏+]

标签:

借鉴他人模板:原文出自:http://www.51cto.com/specbook/11/40222.htm

package com.shiyanlou;

import javax.swing.JFrame;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class Test extends JFrame{

public static void main(String[] args) {
JFrame f = new JFrame("test");
Object[][] row = {{ false,"语文","数学","英语","",""},{ false,"体育","美术","音乐"},{true,"历史","政治","生物"}};
String[] h = { "修改","1", "2", "3","4", "5", };
DefaultTableModel dtm = new DefaultTableModel();
/*
{
@Override

public Class<?> getColumnClass(int c){
return getValueAt(0,c).getClass();
}
@Override
public boolean isCellEditable(int x, int y){
if ( y == 0)
return true;
else
return getValueAt(x,0).toString().equals("true");
}
};
*/
dtm.setDataVector(row,h);
//dtm.addRow(new Object[]{false,"","","","","",});
/*
final JComboBox<String> jcb = new JComboBox<String>();
jcb.addItem("数学");
jcb.addItem("英语");
jcb.addItem("语文");
jcb.setEditable(true);
jcb.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
String s = jcb.getSelectedItem().toString();
if (s.equals(""))
return;
boolean flag = true;
for (int i = 0; i < jcb.getItemCount(); i++){
if (jcb.getItemAt(i).equals(s)){
flag = false;
break;
}
}
if (flag)
jcb.addItem(s);
}
});

*/
JTable tab = new JTable(dtm);
/*
for (int i = 1;i < 6; i++){
tab.getColumnModel().getColumn(i).setCellEditor(new DefaultCellEditor(jcb));
}
*/
f.add(new JScrollPane(tab));
f.pack();
f.setVisible(true);
f.setDefaultCloseOperation(3);
}
}

 

JAVA-setDataVector范例

标签:

原文地址:http://www.cnblogs.com/Hblog/p/5551451.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!