Removing Items from a List
public void actionPerformed(ActionEvent e) {
int index = list.getSelectedIndex();
listModel.remove(index);
int size = listModel.getSize();
if (size == 0) { //Nobody's left, disable firing.
fireButton.setEnabled(false);
} else { //Select an index.
if (index == listModel.getSize()) {
//removed item in last position
index--;
}
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index);
}
}
Tin khác:
- Tìm hiểu quy ước đặt tên thiết bị lưu trữ trong Linux
- Tìm hiểu cấu trúc i-node và cách đọc thông tin tệp tin trong Linux
- Xu hướng mới trong phân tích và thiết kế hệ thống thông tin
- MuZero – Thuật toán Trí tuệ nhân tạo có khả năng tự học mạnh mẽ
- Chủ đề OSCP (Port Redirection and SSH Tunneling) (tiếp theo)