我正在使用JavaFx 2.2.我遇到的问题是我无法在TableView列中放置不同的组件.例如,我有两列
1)答案
2)AnswerType
如果AnswerType包含"Multiple Choice",则Answer Column中的相应单元格应显示ComboBox,否则它应显示TextField.
我在下面有一个代码示例,但它显示的是ComboBox或TextField,但不能同时显示同一列的不同单元格.
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.scene.control.cell.ComboBoxTableCell;
public class TableCellWithMultipleComponent extends Application {
@SuppressWarnings("rawtypes")
TableColumn answerTypeCol;
@SuppressWarnings("rawtypes")
TableColumn answerCol;
ObservableList<String> namesChoiceList;
public static void main(String[] args) {
launch(args);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void start(final Stage primaryStage) {
primaryStage.setTitle("Table Cell With Multiple Components");
TableView<Person> table …Run Code Online (Sandbox Code Playgroud)