我有一个JavaFX表格视图组件,并且正在使用
ComboBox
作为单个列的setGraphic
动态加载数据。我想在cellFactory
中添加ComboBox
。
现在,当用户选择第一个ComboBox
时,下一列ComboBox
必须相应地设置。 为此,我使用了选择侦听器,但是如何获取其他TableColumn
的ComboBox
?
这是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 );
}
}
} );