1
我创建了一个简单的JTable,并希望能够后右键单击它,并用的JMenuItem将禁用所选单元选择在JPopupMenu中的选项来禁用一个小区,这里是我的MouseAdapter:如何使用JPopupmenu的JMenuItem禁用特定的单元格?
private JPopupMenu popup;
private JMenuItem one;
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
int r = table.rowAtPoint(e.getPoint());
if (r >= 0 && r < table.getRowCount()) {
table.setRowSelectionInterval(r, r);
} else {
table.clearSelection();
}
int rowindex = table.getSelectedRow();
if (rowindex < 0)
return;
if (e.isPopupTrigger() && e.getComponent() instanceof JTable) {
int rowIndex = table.rowAtPoint(e.getPoint());
int colIndex = table.columnAtPoint(e.getPoint());
one = new JMenuItem("Disable this cell");
popup = new JPopupMenu();
popup.add(one);
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
});
现在,我知道你可以通过执行禁止特定的细胞(S):
DefaultTableModel tab = new DefaultTableModel(data, columnNames) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
但这是禁止在创建JTable中的单元格,但我需要创建后禁用电池。任何想法/线索如何做到这一点?