I've a JavaFX table view component, and is dynamically loading the data with ComboBox
as setGraphic
for individual columns. I want to added ComboBox
at cellFactory
.
Now when the user select the first ComboBox
, the next column ComboBox
has to be set accordingly. For this purpose I've used a selection listener, but how can I get ComboBox
of other TableColumn
?
Please find the snapshot, of what I need:
Here is the Snippet of 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 );
//initialize
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 ) -> {
//TODO
//How can I get ComboBox of other TableColumn, need to set according to current //selection
} );
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 );
}
}
} );