• Post Reply Bookmark Topic Watch Topic
  • New Topic

help!! on dynamic select box - 2

 
ganeshjk krishnamurthy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Thanks for the reply. I implemented the logic , but it doesnot seem to work.
I am pasting the code below for ur perusal.
Thank you once again.
regards,
ganesh.
public class HelloWorld2 extends JApplet implements ActionListener {

Frame a = new Frame("Deembed");
String data_a[] = { "a" , "b" , "c" };
String data_b[] = { "d" , "e" , "f" };
String data_c[] = { "x" , "y", "z" };
String data[] = { "trans" , "ind" , "cap" };
JComboBox CB2 = new JComboBox(data_a);
public void init()
{
JComboBox CB1 = new JComboBox(data);



this.getContentPane().add(CB1);
this.getContentPane().add(CB2);
this.getContentPane().setLayout(new FlowLayout());
}
public void actionPerformed(ActionEvent e) {

JComboBox cb = (JComboBox)e.getSource();
String data = (String)cb.getSelectedItem();
//process : Add data to CB2
if(data == "ind") {
CB2.removeAllItems();
CB2.addItem(data_b);
}
else if (data== "cap"){
CB2.removeAllItems();
CB2.addItem(data_c);
}
}
}
 
Helen Crosbie
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you may want to do the String comparison using equals() rather than '==', eg. data.equals("ind").
You will probably want another 'else' for when the combo selection goes back to "a".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!