When combo box is selected then display Combo Box and then when any Item in Combo Box is selected then make JTextField visible
Posted
by
Gugz_Singh
on Stack Overflow
See other posts from Stack Overflow
or by Gugz_Singh
Published on 2014-06-10T15:21:57Z
Indexed on
2014/06/10
15:24 UTC
Read the original article
Hit count: 257
I am having trouble with my code. What i'm trying to do is: 1. Create a Check Box, make it visible 2. When Check Box is selected display Combo Box, which will have few items for example ("1","2") 3. When 1 is selected from Combo Box then make 1 Text Field visible 4. When 2 is selected from Combo Box then make 2 Text Field's visible
What I am able to do is when Check Box is clicked, it displays the Combo Box with the items. I am not able provide functionality to the items in the Combo Box, such as when Item1 is clicked then make 1 Text Field visible. Please help needed.
My Code:
public void replacement_used(){
no_of_part_used_label.setVisible(false);
no_part_used_list.setVisible(false);
part_no_one_label.setVisible(false);
part_no_one_field.setVisible(false);
part_no_two_label.setVisible(false);
part_no_two_field.setVisible(false);
part_no_three_label.setVisible(false);
part_no_three_field.setVisible(false);
part_no_four_label.setVisible(false);
part_no_four_field.setVisible(false);
part_no_five_label.setVisible(false);
part_no_five_field.setVisible(false);
HandlerClass handler = new HandlerClass();
replacement_part_check_box.addItemListener(handler);
}
private class HandlerClass implements ItemListener{
public void itemStateChanged(ItemEvent event){
if (replacement_part_check_box.isSelected()){
no_of_part_used_label.setVisible(true);
no_part_used_list.setVisible(true);
}
x();
}
}
public void x(){
System.out.println("Start of x fucntion");
if( no_part_used_list.getSelectedItem().equals("1") ){
System.out.println("It is 1");
part_no_one_label.setVisible(true);
part_no_one_field.setVisible(true);
}
}
© Stack Overflow or respective owner