【问题标题】:When combo box is selected then display Combo Box and then when any Item in Combo Box is selected then make JTextField visible选择组合框时,然后显示组合框,然后选择组合框中的任何项目,然后使JTEXTFIELD可见
【发布时间】:2014-06-10 23:33:33
【问题描述】:

我的代码有问题。我想做的是: 1.创建一个复选框,使其可见 2. 选择复选框时显示组合框,其中将有几个项目,例如(“1”,“2”) 3. 当从 Combo Box 中选择 1 时,使 1 Text Field 可见 4. 当从 Combo Box 中选择 2 时,使 2 Text Field 可见

我能够做的是,当单击复选框时,它会显示带有项目的组合框。 我无法为组合框中的项目提供功能,例如当单击 Item1 时使 1 个文本字段可见。 请帮助需要。

我的代码:

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

}

私有类HandlerClass实现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();
    }

}

公共无效 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);

    }


}

【问题讨论】:

    标签: java user-interface checkbox combobox


    【解决方案1】:

    您需要做的就是向您的 ComboBox 添加一个 ActionListener。 可能首先您应该浏览此链接,以便您可以了解在摇摆http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html 中使用组合框的基础知识 您还需要学习编码约定,以便您的代码变得更具可读性和可理解性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 2017-08-09
      • 1970-01-01
      • 2018-02-05
      相关资源
      最近更新 更多