2014-04-16 5 views
0

내 코드에 TextField와 ComboBox가 있습니다. 두 컨트롤에 값이있을 때 버튼을 실행 가능하게해야합니다. 내 코드는 -ComboBox의 TextField.textProperty()에 해당하는 항목은 무엇입니까?

addSubName = new TextField(); 
    addSubName.setPromptText("Staff Name"); 
    addSubName.setPrefSize(200, 30); 

    comboBox1 = new ComboBox(); 
    comboBox1.setPromptText("Choose Subject"); 
    comboBox1.setPrefSize(280, 30); 

    BooleanBinding bb = new BooleanBinding() { 
    { 
     super.bind(addSubName.textProperty()); 
    } 

    @Override 
    protected boolean computeValue() { 
     return (addSubName.getText().isEmpty()); 
     } 
    }; 

    final Button b2 = new Button("Add"); 
    b2.setFont(Font.font("Calibri", FontWeight.BOLD, 17)); 
    b2.setPrefSize(70, 30); 
    b2.setStyle(" -fx-base: #0066ff;"); 
    b2.setTextFill(Color.BLACK); 
    b2.disableProperty().bind(bb); 

당신이 본 것처럼, 나는 버튼이 비활성화되도록 TextField가 비어 있는지 여부를 확인하는 방법을 알고 있습니다. ComboBox도 확인해야합니다. ComboBox에 대해 "textProperty()"및 "getText(). isEmpty()"와 동일한 것은 무엇입니까?

답변

2

ComboBoxvalueProperty입니다. (

+0

b2.disableProperty에서 :

b2.disableProperty().bind(bb.or(Bindings.isNull(comboBox1.valueProperty()))); 

이 (

BooleanBinding bb = Bindings.isEmpty(addSubName.textProperty()); 

자바 FX 8에서 너무 텍스트에 바인딩 API를 사용할 수 있습니다)

현재 바인딩 API를 사용할 수) .bind (bb.or (Bindings.isNull (comboBox1.valueProperty())))); Bindings는 오류로 표시됩니다. – TomJ

+0

무엇이 오류입니까? –

관련 문제