java/swing
[swing] - JTable 에 JComboBox 삽입하기
짱가쟁이
2010. 6. 30. 09:20
<실행화면>
Cell Editor 를 콤보박스로 변경하는 단순한 형태의 코드.
changeCellEditor(table,
table.getColumnModel().getColumn(3));
void changeCellEditor(JTable table, TableColumn column) {
void changeCellEditor(JTable table, TableColumn column) {
JComboBox comboBox = new JComboBox();
comboBox.addItem("사람");
comboBox.addItem("요크");
comboBox.addItem("마르티스");
comboBox.addItem("MIX");
column.setCellEditor(new DefaultCellEditor(comboBox));
DefaultTableCellRenderer renderer =
new
DefaultTableCellRenderer();
renderer.setToolTipText("클릭하면
콤보박스로 변경됩니다.");
column.setCellRenderer(renderer);
}
위 코드 샘플의 bold line 이 cell editor 를 변경하는 부분이다.
출처