0

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 have also tried this post:How to hide or deactivate a TextField and a Label with javafx

still its not working..

Community
  • 1
  • 1
  • Is this statement `"play control"` is printed in the console, when you are running the program – Clement Amarnath Jun 28 '16 at 07:16
  • yes.. its printed.. but the if conditon is not working –  Jun 28 '16 at 07:54
  • if the statement `"play control"' is printed then your code should work. Post your complete code for more debugging. – Clement Amarnath Jun 28 '16 at 08:09
  • plse check. full controller class code is added.. what i meant to do is if in the form i select a particular combobox selection textfield and its associated label should be disabled. –  Jun 28 '16 at 08:16
  • Are you aware of the difference between [editable](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TextInputControl.html#editableProperty) and [disable](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/Node.html#disableProperty)? Which one do you need? – Oliver Jan Krylow Jun 28 '16 at 08:17
  • Do yourself and everyone else a favour and use long variable names ;) https://signalvnoise.com/posts/3250-clarity-over-brevity-in-variable-and-method-names – Oliver Jan Krylow Jun 28 '16 at 08:19
  • yes.. i know.. any one is okay with me..#OJKrylow –  Jun 28 '16 at 08:24

1 Answers1

0

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

if(cmb2.getSelectionModel().getSelectedItem().equals("Uwt-0"))
PrashantP
  • 182
  • 1
  • 12
  • one more thing prashantP.. i forgot to ask you.. like bootstrap templates are there any fxml templates or javafx templates –  Jun 29 '16 at 07:31
  • I haven't found any templates yet. Please let me know if you find any. :) – PrashantP Jul 04 '16 at 09:20