我想通过我的JavaFX应用程序中的组合框中预定义的特定选择来停用TextField及其Label。 我已经尝试过以下代码,但它不起作用..
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);
}
}
} 我也试过这篇文章:How to hide or deactivate a TextField and a Label with javafx
仍然不起作用..
答案 0 :(得分:0)
请将“==”更改为“等于(obj)”并检查。
if(cmb2.getSelectionModel().getSelectedItem().equals("Uwt-0"))