日期:2014-05-20 浏览次数:20728 次
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class FF {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FF window = new FF();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public FF() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane scrollPane = new JScrollPane();
JTable tab = new JTable();
CustomModel mod = new CustomModel();
mod.addColumn("选择");
mod.addColumn("课程编号");
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
Object[] data = {new Boolean(false),"03"};
Object[] data1 = {new Boolean(false),"04"};
mod.addRow(data);
mod.addRow(data1);
tab.setModel(mod);
scrollPane.getViewport().add(tab);
}
class CustomModel extends DefaultTableModel {
public boolean isCellEditable(int row, int column) {
if (column > 0) {
return false;
} else {
return true;
}
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
}
}