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中的單元格,但我需要創建後禁用電池。任何想法/線索如何做到這一點?