Zolf
asked on
Multiple Combo box load dynamically
hello there,
i have 3 combo box which should display data based on selecting another CB.i mean when i select a value from the first combo box,the second combo box should get filled with data related to cb1,then again combo box 3 should get filled with data based on the second cb selection.how can i do this.
cheers
zolf
i have 3 combo box which should display data based on selecting another CB.i mean when i select a value from the first combo box,the second combo box should get filled with data related to cb1,then again combo box 3 should get filled with data based on the second cb selection.how can i do this.
cheers
zolf
add this
comboBox2.setSelectedIndex (0);
just after
comboBox2.setModel(mdlFunc tions.fill ComboBoxID (queryKol, connect,"k olid","Kol Descriptio n"));
comboBox2.setSelectedIndex
just after
comboBox2.setModel(mdlFunc
ASKER
when i add a new value in the cb. i update the cb to show the new value in it.to do this i remove the items in the cb and again fill it with new values.now the problem is when i remove the cb.the action listener of the cb is called which gives this error.which is true because the cb is empty
Exception occurred during event dispatching:
java.lang.IllegalArgumentE
at javax.swing.JComboBox.setS
at src.com.FormFinance$2.acti
at javax.swing.JComboBox.fire
at javax.swing.JComboBox.cont
at javax.swing.JComboBox.inte
at javax.swing.AbstractListMo
at javax.swing.DefaultComboBo
at javax.swing.JComboBox.remo
at src.com.FormFinance.update
at src.com.AddNewKol$1.action
at javax.swing.AbstractButton
at javax.swing.AbstractButton
at javax.swing.DefaultButtonM
at javax.swing.DefaultButtonM
at javax.swing.plaf.basic.Bas
at java.awt.Component.process
at javax.swing.JComponent.pro
at java.awt.Component.process
public FormFinance(Connection srcCN,JFrame getParentFrame) throws SQLException
{
//Set the form caption and some properties start
super("Finance",
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable
//End set the form caption and some properties
JFParentFrame = getParentFrame;
connect = MainForm.getDBConnection();
container = getContentPane();
container.setLayout(new BorderLayout());
//Start initialize variables
JPLeftContainer.setLayout(new BorderLayout());
JPRightContainer.setLayout(null);
//-- Add the JLPicture1
JLPicture1.setBounds(5,5,48,48);
JPRightContainer.add(JLPicture1);
pleaseFillupAllLabel = mdl.setJLabel(pleaseFillupAllLabel, 55, 5, 255, 42);
label1 = mdl.setJLabel(label1, 55, 50, 55, 25);//add40 for y
label2 = mdl.setJLabel(label2, 55, 90, 55, 25);
label3 = mdl.setJLabel(label3, 55, 130, 55, 25);
label4 = mdl.setJLabel(label4, 55, 170, 55, 25);
label5 = mdl.setJLabel(label5, 55, 210, 55, 25);
label6 = mdl.setJLabel(label6, 55, 250, 55, 25);
//tf1 = mdl.setJTextField(tf1, 150, 90, 255, 25);
//tf2 = mdl.setJTextField(tf2, 150, 130, 255, 25);
tf3 = mdl.setJTextField(tf3, 150, 170, 255, 25);
//tf4 = mdl.setJTextField(tf4, 150, 210, 255, 25);
tf11 = mdl.setJTextField(tf11, 455, 90, 55, 25);
tf22 = mdl.setJTextField(tf22, 455, 130, 55, 25);
tf33 = mdl.setJTextField(tf33, 455, 170, 55, 25);
//tf44 = mdl.setJTextField(tf44, 450, 210, 55, 25);
JTabbedPane tabPane = new JTabbedPane();
JPanel cityPane = new JPanel();
cityPane.setBackground(Color.GREEN);
JPanel statePane = new JPanel();
statePane.setBackground(Color.BLUE);
JPanel wPane = new JPanel();
wPane.setBackground(Color.RED);
tabPane.addTab(" cityPane ", cityPane);
tabPane.addTab(" statePane ", statePane);
tabPane.addTab(" www Pane ", wPane);
tQuery = "select glid,GLDescription from GeneralLegder order by GLID";
//comboBox1 = mdlFunctions.fillComboID(tQuery,connect,"glid","GLDescription");
comboBox1 = mdlFunctions.fillComboID(tQuery,connect,"glid","GLDescription");
comboBox1.setBounds(150, 50, 255, 25);
final long id;
MyType data = (MyType)comboBox1.getSelectedItem();
id = data.getId(); // here is your id
//System.out.println(id);
final String queryKol = "Select kolid,KolDescription FROM KolTotal WHERE glid ="+id;
System.out.println(queryKol);
comboBox2 = mdlFunctions.fillComboID(queryKol,connect,"kolid","KolDescription");
comboBox2.setBounds(150, 90, 255, 25);
comboBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if(e.getSource() instanceof JComboBox)
{
System.out.println("combo Box 1 ");
MyType data;
long id = 1;
if(flag)
{
//data = (MyType)comboBox1.getSelectedItem();
System.out.println(flag);
comboBox1.setSelectedIndex(0);
data = (MyType)comboBox1.getSelectedItem();
id = data.getId();
}
else
{
System.out.println(flag);
data = (MyType)comboBox1.getSelectedItem();
id = data.getId(); // here is your id
}
final String queryKol = "Select kolid,KolDescription FROM KolTotal WHERE glid ="+id;
System.out.println(queryKol);
comboBox2.setModel(mdlFunctions.fillComboBoxID(queryKol,connect,"kolid","KolDescription"));
System.out.println("combo box 2"+comboBox2.getSelectedItem());
Object obj = comboBox2.getSelectedItem();
System.out.println("combo box 2 "+obj);
if(obj == null)
{
System.out.println("if "+obj);
comboBox3.removeAllItems();
}
else
{
System.out.println("else "+obj);
MyType data1 = (MyType)comboBox2.getSelectedItem();
long id1 = data1.getId(); // here is your id
final String queryMohin = "Select Mohinid,MohinDescription FROM Mohin WHERE kolid ="+id1;
System.out.println(queryMohin);
comboBox3.setModel(mdlFunctions.fillComboBoxID(queryMohin,connect,"Mohinid","MohinDescription"));
}
}
}
});
final long kolid;
MyType data1 = (MyType)comboBox2.getSelectedItem();
kolid = data1.getId(); // here is your id
//System.out.println(id);
final String queryMohin = "Select Mohinid,MohinDescription FROM Mohin WHERE kolid ="+kolid;
System.out.println(queryMohin);
comboBox3 = mdlFunctions.fillComboID(queryMohin,connect,"Mohinid","MohinDescription");
comboBox3.setBounds(150, 130, 255, 25);
comboBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if(e.getSource() instanceof JComboBox)
{
System.out.println("combo box 2"+comboBox2.getSelectedItem());
MyType data = (MyType)comboBox2.getSelectedItem();
long id = data.getId(); // here is your id
final String queryMohin = "Select Mohinid,MohinDescription FROM Mohin WHERE kolid ="+id;
System.out.println(queryMohin);
comboBox3.setModel(mdlFunctions.fillComboBoxID(queryMohin,connect,"Mohinid","MohinDescription"));
}
}
});
================================================================
public static void updateComboBox()
{
System.out.println(comboBox1.getItemCount());
flag = true;
for( int i = 0; i < comboBox1.getItemCount(); i++ )
{
System.out.println(comboBox1.getItemAt(i));
}
System.out.println("Before remove "+comboBox1.getItemCount());
comboBox1.removeAllItems();
System.out.println("After remove "+comboBox1.getItemCount());
//comboBox1 = mdlFunctions.fillComboID(tQuery,connect,"glid","GLDescription");
JComboBox temp = mdlFunctions.fillComboID(tQuery,connect,"glid","GLDescription");
System.out.println(temp.getItemCount());
for( int i = 0; i < temp.getItemCount(); i++ )
{
comboBox1.addItem(temp.getItemAt(i));
}
}
ASKER
before adding the new values the action listener of cb1 is called in void updateComboBox()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks mate
ASKER
i have this code which works partly.the problem is hen i select a value in the cb1 the cb2 takes new values.but cb3 does not take the new value. but when i select cb2 then cb3 takes new values.please help
tQuery = "select glid,GLDescription from GeneralLegder order by GLID";
//comboBox1 = mdlFunctions.fillComboID(t
comboBox1 = mdlFunctions.fillComboID(t
comboBox1.setBounds(150, 50, 255, 25);
final long id;
MyType data = (MyType)comboBox1.getSelec
id = data.getId(); // here is your id
System.out.println(id);
final String queryKol = "Select kolid,KolDescription FROM KolTotal WHERE glid ="+id;
System.out.println(queryKo
comboBox2 = mdlFunctions.fillComboID(q
comboBox2.setBounds(150, 90, 255, 25);
comboBox1.addActionListene
public void actionPerformed(ActionEven
{
if(e.getSource() instanceof JComboBox)
{
System.out.println("combo Box 1 ");
MyType data = (MyType)comboBox1.getSelec
long id = data.getId(); // here is your id
final String queryKol = "Select kolid,KolDescription FROM KolTotal WHERE glid ="+id;
System.out.println(queryKo
comboBox2.setModel(mdlFunc
}
}
});
final long kolid;
MyType data1 = (MyType)comboBox2.getSelec
kolid = data1.getId(); // here is your id
System.out.println(id);
final String queryMohin = "Select Mohinid,MohinDescription FROM Mohin WHERE kolid ="+kolid;
System.out.println(queryMo
comboBox3 = mdlFunctions.fillComboID(q
comboBox3.setBounds(150, 130, 255, 25);
comboBox2.addActionListene
public void actionPerformed(ActionEven
{
if(e.getSource() instanceof JComboBox)
{
System.out.println("combo box 2"+comboBox2.getSelectedIt
MyType data = (MyType)comboBox2.getSelec
long id = data.getId(); // here is your id
final String queryMohin = "Select Mohinid,MohinDescription FROM Mohin WHERE kolid ="+id;
System.out.println(queryMo
comboBox3.setModel(mdlFunc
}
}
});