如何在javafx中通过Combobox选择停用TextField和Label [英] How to deactivate a TextField and a Label by Combobox selection in javafx

查看:374
本文介绍了如何在javafx中通过Combobox选择停用TextField和Label的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过我的JavaFX应用程序中我的组合框中预定义的特定选项来停用一个TextField及其Label。
i已经尝试了下面的代码,但它不工作。

I would like to deactivate a TextField and its Label by a specific selection pre defined in my combobox in my JavaFX application. i have already tried the below code but its not working..

   public class Controller extends Application {
    @FXML
    private ComboBox<String>cmb1;
    @FXML
    private ComboBox<String>cmb2;
    @FXML
    private Button btn1,btn2;
    @FXML
    private TextField tf1,tf2,tf3,tf4,tf5,tf6;
    @FXML
    String v1,v2,v3,v4,v5,v6,cm1,cm2;
    @FXML
    private Label l6,l7;

    @Override
    public void start(Stage primaryStage) throws Exception {
    }

    private void play()
    {
        String check="Uwt-0";
        System.out.println("play control");
        tf5.setEditable(false);
        tf6.setEditable(false);
        //tf5.setVisible(false);
        //tf6.setVisible(false);
    }
    public void submit(ActionEvent event) {

        System.out.println("Submit Button Pressed");
        v1=tf1.getText();
        v2=tf2.getText();
        v3=tf3.getText();
        v4=tf4.getText();
        v5=tf5.getText();
        v6=tf6.getText();

        cm1=cmb1.getSelectionModel().getSelectedItem();
        cm2=cmb2.getSelectionModel().getSelectedItem();
        if(v1.isEmpty()||v2.isEmpty()||v3.isEmpty()||v4.isEmpty()||v5.isEmpty()||v6.isEmpty()||cmb1.getSelectionModel().getSelectedItem()==null||null==cmb2.getSelectionModel().getSelectedItem())
        {
            AlertBox.display("Error Dialouge", "Set All The Parameters");
               System.out.println("Submit Button Clicked Without Filling All Parameters..");
        }
        else
        {   
        System.out.println(v1 +"\n"+ v2+"\n"+v3+"\n"+cm1+"\n"+cm2+"\n"+v4+"\n"+v5+"\n"+v6);
        }
    }
    public void clear(ActionEvent event)
    {
        System.out.println("Clear Button Pressed");
        tf1.setText(null);
        tf2.setText(null);
        tf3.setText(null);
        tf4.setText(null);
        tf5.setText(null);
        tf6.setText(null);

        cmb1.setValue(null);
        cmb2.setValue(null);
    }
    //Action for second combobox fx:id-cmb2
    public void handle(ActionEvent event)
    {
        System.out.println("Control Here");
        if(cmb2.getSelectionModel().getSelectedItem()=="Uwt-0")
        {

        tf5.setEditable(false);
        tf6.setEditable(false);
        }
    }

}
i也试过这个帖子: 如何隐藏或停用TextField和一个带有javafx的标签

仍然无效。

推荐答案

请将==改为equals(obj)并检查。

Please change "==" to "equals(obj)" and check.

if(cmb2.getSelectionModel().getSelectedItem().equals("Uwt-0"))

这篇关于如何在javafx中通过Combobox选择停用TextField和Label的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆