JTable 02
public class DataModelTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
String rows[][] = { { "수곡동", "야구" }, { "모충동", "족구" }, { "개신동", "축구" } };
String headers[] = { "이름", "종목" };
String sports[] = { "야구", "축구", "족구", "기타" };
JComboBox<String> comboBox = new JComboBox<String>(sports);
comboBox.setMaximumRowCount(4);
TableCellEditor editor = new DefaultCellEditor(comboBox);
JFrame frame = new JFrame("JTable test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTable table = new JTable(new DefaultTableModel(rows, headers));
table.getColumnModel().getColumn(1).setCellEditor(editor);
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(300, 150);
frame.setVisible(true);
}
}