• Post Reply Bookmark Topic Watch Topic
  • New Topic

help on dynamic select box  RSS feed

 
ganeshjk krishnamurthy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I am new to java and am developing an application . I need suggestions to implement the requirement below.
The application will have a combo box ( CB1) with 3 choices A , B and C. Another combobox (CB2) in the same frame has to reflect the choice selected in CB1. I.e for example if A is selected in CB1 then CB2 has to display D , E , F ..... if B is selected then CB2 has to display G, H and I .....
Please guide me to the solution.
Hoping to hear a solution as quickly as possible.
Thank you.
regards,
ganesh.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Create CB1 and CB2

2. Add data to CB1 and addActionListener
if action is happened in CB1 , then create data for add to CB2


this code will help you...
 
Surasak Leenapongpanit
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ganeshjk,
In the CB1's actionPerformed(ActionEvent e) method.
 
ganeshjk krishnamurthy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Thanks for the help. I tried your suggestions , but still am not able to get the result.Here is the code for ur perusal.import java.applet.*;
import java.lang.*;
import java.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

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);
}
}
}

thank you ,
regards,
ganesh.
 
ganeshjk krishnamurthy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ganeshjk krishnamurthy:
hi,
Thanks for the help. I tried your suggestions , but still am not able to get the result.Here is the code for ur perusal.import java.applet.*;
import java.lang.*;
import java.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

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);
}
}
}

thank you ,
regards,
ganesh.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!