如何让JTable不可编辑

2024-12-27 09:19:26
推荐回答(1个)
回答1:

import javax.swing.*;
import java.awt.*;
import javax.swing.table.DefaultTableModel;

public class Test extends JFrame {

public static void main(String[] args) {
JFrame jframe = new JFrame();
jframe.setBounds(50, 50, 200, 300);

DefaultTableModel tableModel = new DefaultTableModel(100, 100);
JTable jTable=new JTable(tableModel){
public boolean isCellEditable(int row, int column) {
return false;
}
};

jframe.getContentPane().add(jTable);
jframe.setLayout(new FlowLayout());
jframe.setVisible(true);
}
}