import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class main implements ItemListener {
String[] a = {"one","two","three"};
String[] b = {"4","5","6"};
String[] c = {"7","8","9"};
String[] d = {"10","11","12"};
String[] e = {"13","14","15"};
JComboBox a1 = new JComboBox(a);
JComboBox b1 = new JComboBox(b);
JComboBox c1 = new JComboBox(c);
main()
{
String[] col = {"ID","NAME","Address"};
DefaultTableModel dt = new DefaultTableModel(col,100);
JTable table = new JTable(dt);
table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(a1));
table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(b1));
table.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(c1));
a1.addItemListener(this);
b1.addItemListener(this);
c1.addItemListener(this);
JScrollPane js = new JScrollPane(table);
JFrame f = new JFrame("Test");
f.add(js);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public static void main(String[] args) {
main m = new main();
}
public void itemStateChanged(ItemEvent e) {
if(e.getSource() == a1)
{
}
}
}
Problem is i want user to select column1 first then he choose column2 according to column1 and column3 then.... But above code is a free excel type you can select any column in any row.......