netbeans에서 Jtable의 셀에 버튼을 추가하는 방법 ???netbeans에서 Jtable의 셀에 버튼을 추가
1
A
답변
0
버튼 상태가 변경되면 사용자 정의 셀 렌더러를 추가하고 테이블에서 일부 이벤트의 대상을 다시 지정하고 셀을 다시 칠해야합니다. 그것은 악한 일이지만 더러운 일이지만 끝날 수 있습니다.
2
0
Button Table Example에 표시된대로 JButton
을 확장하고 TableCellRenderer
을 구현하는 클래스를 만듭니다.
class ButtonRenderer extends JButton implements TableCellRenderer {
public ButtonRenderer() {
setOpaque(true);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());
setBackground(table.getSelectionBackground());
} else {
setForeground(table.getForeground());
setBackground(UIManager.getColor("Button.background"));
}
setText((value == null) ? "" : value.toString());
return this;
}
}
또한 열의 셀 편집기도 만들어야합니다.
class ButtonEditor extends DefaultCellEditor {
protected JButton button;
private String label;
private boolean isPushed;
public ButtonEditor(JCheckBox checkBox) {
super(checkBox);
button = new JButton();
button.setOpaque(true);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fireEditingStopped();
}
});
}
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
if (isSelected) {
button.setForeground(table.getSelectionForeground());
button.setBackground(table.getSelectionBackground());
} else {
button.setForeground(table.getForeground());
button.setBackground(table.getBackground());
}
label = (value == null) ? "" : value.toString();
button.setText(label);
isPushed = true;
return button;
}
public Object getCellEditorValue() {
if (isPushed) {
//
//
JOptionPane.showMessageDialog(button, label + ": Ouch!");
// System.out.println(label + ": Ouch!");
}
isPushed = false;
return new String(label);
}
public boolean stopCellEditing() {
isPushed = false;
return super.stopCellEditing();
}
protected void fireEditingStopped() {
super.fireEditingStopped();
}
}
셀이 해당 열 및 셀 편집기로 ButtonEditor의 인스턴스에 대한 렌더링으로 우리는 다음 ButtonRender
의 인스턴스를 설정합니다.
\\"Button" is the column name
table.getColumn("Button").setCellRenderer(new ButtonRenderer());
table.getColumn("Button").setCellEditor(
new ButtonEditor(new JCheckBox()));
제공된 링크의 example에는 완전한 실행 가능한 예가 있습니다.
관련 문제
- 1. NetBeans에서 JTable의 데이터 채우기
- 2. netbeans에서 Jtable의 개별 열 너비
- 3. 데이터와 함께 JTable의 셀 안에 버튼을 추가 하시겠습니까?
- 4. 있는 UIButton 내가있는 tableview 셀에 버튼을 추가 한
- 5. 어떻게 커스텀 셀에 버튼을 추가 할 수 있습니까?
- 6. UITableView 셀에 UIPageControll 추가
- 7. JTable의 특정 셀에 dropdownbox를 추가하는 방법, microsoft excel 같은 것을?
- 8. DataGrid의 셀에 팝업으로 추가 정보 추가
- 9. 버튼을 눌렀을 때 사운드를 재생하는 테이블 뷰 셀에 버튼을 놓았지만
- 10. JTable의 셀 편집
- 11. JTable의 자동 필터링
- 12. JTable의 - 라인
- 13. JTable의 ResultSet
- 14. JTable의 셀
- 15. 안녕하세요 JTable의
- 16. JTable의 MouseMotionListener
- 17. 스크롤 JTable의
- 18. JTable의 UTF-8
- 19. 동적으로 버튼을 추가 하시겠습니까?
- 20. Jtable의 행에 어떻게 테두리를 추가합니까?
- 21. 테이블 셀에 아이콘 + 컨테이너 데이터 추가
- 22. DataGrid 셀에 작은 색 사각형 추가
- 23. ASP.net 그리드 컨트롤 셀에 마우스 오버 추가
- 24. iTextSharp 단일 셀에 텍스트와 바코드 추가?
- 25. datagridview의 특정 셀에 행 메모 추가
- 26. iPhone 질문 : 어떻게하면 테이블 뷰 셀에 버튼을 추가 할 수 있습니까?
- 27. NetBeans에서 텍스트 필드 비활성화
- 28. JTree와 JTable의 혼합을 만드는 방법은?
- 29. 플렉스 4 - 셀에 버튼이있는 DataGrid
- 30. 버튼을 사용하여 추가 정보 저장
위대한 사람 나는 그것을 발견 .... 당신의 도움을 많이 주셔서 감사합니다! – Jasra