java gui中如何对jtable的某一个列禁止修改
- 提问者网友:雪舞兮
- 2021-05-01 03:35
- 五星知识达人网友:几近狂妄
- 2021-05-01 04:00
你要的应该是这种效果吧.......
public class Frame1
extends JFrame {
BorderLayout borderLayout1 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JTable jTable1 = new JTable();
public Frame1() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
DefaultTableModel model = new MyTableModel();
String col1[] = {
"a", "b", "c", "d", "e"};
String col2[] = {
"f", "g", "h", "i", "j"};
model.addColumn("a", col1);
model.addColumn("b", col2);
jTable1.setModel(model);
getContentPane().setLayout(borderLayout1);
this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTable1);
this.setSize(500, 500);
this.setVisible(true);
}
public static void main(String[] args) {
new Frame1();
}
}
class MyTableModel
extends DefaultTableModel {
public boolean isCellEditable(int row, int column) {
return column==0?false:true;
}
}