Monday, January 15, 2018

JAVAFX - How bind controls by properties

Suppose this .fxml form:











Add this code to form controller initialize() method:
public class FXMLMainController implements Initializable {  
  @FXML private ChoiceBox< javafx.geometry.side > choiceBox;
  @FXML private TabPane tabPane;
  
  @Override
  public void initialize( URL url, ResourceBundle rb ) {
    choiceBox.getItems().addAll( javafx.geometry.Side.values() );        
    choiceBox.setValue( Side.TOP );
    
    tabPane.sideProperty().bind( choiceBox.valueProperty() );
  }  
  
}

How you can see, tabPane.side property is binded to choicebox.value - so, after change in choicebox.value is immediately changed tabPane.side.

No comments:

Post a Comment