You are on page 1of 2

Hi, Requirement Description: I need a Jtable which have different combo boxes in the column SmallestTrack.

But all comboBoxes have different Items and also different number of items. Once we click on each combobox , respective item should be displayed and single item must be selected by the user. The selected item will be displayed in the combobox. The Number of rows are not fixed it may vary, depends on requirement. Problem Description: When I select the ComboBox it will shows the Item but when I select next combobox the items are the same as in the first combobox. Code I used: TableColumn tcolor = table.getColumnModel().getColumn(2); tcolor.setCellRenderer(new CustomTableColumnRenderer()); public class CustomTableColumnRenderer extends DefaultTableCellRenderer { int x; public Component getTableCellRendererComponent (JTable table, Object obj, boolean isSelected, boolean hasFocus, int row, int column) { Component col = super.getTableCellRendererComponent( table, obj, isSelected, hasFocus, row, column); x=row; final JComboBox comboBox = new JComboBox(); if(isSelected) { TableColumn fin = table.getColumnModel().getColumn(column); // To get required column comboBox.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ // Action listener for comboBox comboBox.removeAllItems(); ArrayList<String> track = apeSort(layer.get(x)); // to get the track list from database for(int d=0;d<track.size();d++) comboBox.addItem(track.get(d)); } }); fin.setCellEditor(new DefaultCellEditor(comboBox)); } return this; } } Please check the requirement example below. Actually all Combobox items are retrieved from database.

ComboBox1 Items: 1) 2) 3) 4) Canada Banglore Mexico New York

ComboBox2 Items: 1) eye 2) Kidney 3) Heart ComboBox3 Items: 1) mm 2) Inch 3) Centi 4) Deci 5) Meter ComboBox4 Items: 1) Fan 2) Mirror ComboBox5 Items: 1) John 2) King 3) Kim 4) Pedrson 5) Swat 6) Mick

You might also like