Skip to content

Instantly share code, notes, and snippets.

@james-d
Created May 15, 2015 17:39
Show Gist options
  • Save james-d/147ce9c04af215788e9a to your computer and use it in GitHub Desktop.
Save james-d/147ce9c04af215788e9a to your computer and use it in GitHub Desktop.
Binding a table column header text to a combo box.
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class BoundTableColumnHeader extends Application {
@Override
public void start(Stage primaryStage) {
ComboBox<String> combo = new ComboBox<>(FXCollections.observableArrayList("One", "Two", "Three"));
combo.setValue("One");
TableView<Void> table = new TableView<>();
TableColumn<Void, Void> col = new TableColumn<>();
table.getColumns().add(col);
col.textProperty().bind(combo.valueProperty());
BorderPane root = new BorderPane(table, combo, null, null, null);
Scene scene = new Scene(root, 400, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment