I have a JavaFX table view component and dynamically load data with ComboBoxboth setGraphicfor individual columns. I want to add ComboBoxin cellFactory.
Now that the user selects the first ComboBox, the next column ComboBoxshould be set accordingly. I used a select listener for this, but how can I get ComboBoxothers TableColumn?
Find the snapshot that I need:

Here is a snippet TableView:
TableColumn< ModelInput, String > colCalibration = new TableColumn<>( "Calibration" );
TableColumn< ModelInput, String > colSamplingX = new TableColumn<>( "Sampling point X" );
TableColumn< ModelInput, String > colSamplingY = new TableColumn<>( "Sampling point Y" );
List< TableColumn< ModelInput, String > > tableColList =
Stream.of( colCalibration, colSamplingX, colSamplingY )
.collect( Collectors.toList() );
tableviewCalibMatching.getColumns().addAll( tableColList );
colCalibration.setCellFactory( param -> new TableCell< ModelInput, String >() {
@Override
public void updateItem( String item, boolean empty ) {
super.updateItem( item, empty );
if( empty ) {
setText( null );
} else {
ComboBox< String > comboBoxCalibMatchingNames = new ComboBox<>( listCalibNames );
comboBoxCalibMatchingNames.setPrefWidth( splitWidth );
comboBoxCalibMatchingNames.getSelectionModel().selectedItemProperty()
.addListener( (ChangeListener< String >)( observable, oldValue,
newValue ) -> {
} );
setGraphic( comboBoxCalibMatchingNames );
setContentDisplay( ContentDisplay.GRAPHIC_ONLY );
}
}
} );
colSamplingX.setCellFactory( param -> new TableCell< ModelInput, String >() {
@Override
public void updateItem( String item, boolean empty ) {
super.updateItem( item, empty );
if( empty ) {
setText( null );
} else {
final ComboBox< String > comboBox = new ComboBox<>();
setGraphic( comboBox );
setContentDisplay( ContentDisplay.GRAPHIC_ONLY );
}
}
} );
colSamplingY.setCellFactory( param -> new TableCell< ModelInput, String >() {
@Override
public void updateItem( String item, boolean empty ) {
super.updateItem( item, empty );
if( empty ) {
setText( null );
} else {
final ComboBox< String > comboBox = new ComboBox<>();
setGraphic( comboBox );
setContentDisplay( ContentDisplay.GRAPHIC_ONLY );
}
}
} );
source
share