Example usage for javafx.scene.control TableView TableView

List of usage examples for javafx.scene.control TableView TableView

Introduction

In this page you can find the example usage for javafx.scene.control TableView TableView.

Prototype

public TableView(ObservableList<S> items) 

Source Link

Document

Creates a TableView with the content provided in the items ObservableList.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Table View Sample");
    stage.setWidth(300);//from ww  w  .j a va2  s.c  o  m
    stage.setHeight(500);

    final Label label = new Label("Student IDs");
    label.setFont(new Font("Arial", 20));

    TableColumn<Map, String> firstDataColumn = new TableColumn<>("Class A");
    TableColumn<Map, String> secondDataColumn = new TableColumn<>("Class B");

    firstDataColumn.setCellValueFactory(new MapValueFactory(Column1MapKey));
    firstDataColumn.setMinWidth(130);
    secondDataColumn.setCellValueFactory(new MapValueFactory(Column2MapKey));
    secondDataColumn.setMinWidth(130);

    TableView tableView = new TableView<>(generateDataInMap());

    tableView.setEditable(true);
    tableView.getSelectionModel().setCellSelectionEnabled(true);
    tableView.getColumns().setAll(firstDataColumn, secondDataColumn);
    Callback<TableColumn<Map, String>, TableCell<Map, String>> cellFactoryForMap = (
            TableColumn<Map, String> p) -> new TextFieldTableCell(new StringConverter() {
                @Override
                public String toString(Object t) {
                    return t.toString();
                }

                @Override
                public Object fromString(String string) {
                    return string;
                }
            });
    firstDataColumn.setCellFactory(cellFactoryForMap);
    secondDataColumn.setCellFactory(cellFactoryForMap);

    final VBox vbox = new VBox();

    vbox.setSpacing(5);
    vbox.setPadding(new Insets(10, 0, 0, 10));
    vbox.getChildren().addAll(label, tableView);

    ((Group) scene.getRoot()).getChildren().addAll(vbox);

    stage.setScene(scene);

    stage.show();
}

From source file:de.pixida.logtest.designer.logreader.LogReaderEditor.java

public LogReaderEditor(final IMainWindow mainWindow) {
    super(Editor.Type.LOG_READER_CONFIG, mainWindow);

    this.parsedLogEntries = new TableView<>(this.parsedLogEntryItems);
    this.parsedLogEntries.setPlaceholder(new Text("No log entries to display."));
    final TableColumn<LogEntryTableRow, String> lineNoCol = new TableColumn<LogEntryTableRow, String>("LineNo");
    lineNoCol.setCellValueFactory(new PropertyValueFactory<>("lineNumber"));
    lineNoCol.setSortable(false);//from   w w  w .j a  v a2s .  co  m
    lineNoCol.setGraphic(Icons.getIconGraphics("key"));
    final TableColumn<LogEntryTableRow, String> timeCol = new TableColumn<LogEntryTableRow, String>("Time");
    timeCol.setCellValueFactory(new PropertyValueFactory<>("time"));
    timeCol.setSortable(false);
    timeCol.setGraphic(Icons.getIconGraphics("clock"));
    final TableColumn<LogEntryTableRow, String> channelCol = new TableColumn<LogEntryTableRow, String>(
            "Channel");
    channelCol.setCellValueFactory(new PropertyValueFactory<>("channel"));
    channelCol.setSortable(false);
    channelCol.setGraphic(Icons.getIconGraphics("connect"));
    final TableColumn<LogEntryTableRow, String> payloadCol = new TableColumn<LogEntryTableRow, String>(
            "Payload");
    payloadCol.setCellValueFactory(new PropertyValueFactory<>("payload"));
    payloadCol.setSortable(false);
    payloadCol.setGraphic(Icons.getIconGraphics("page_white_text_width"));
    this.parsedLogEntries.getColumns().add(lineNoCol);
    this.parsedLogEntries.getColumns().add(timeCol);
    this.parsedLogEntries.getColumns().add(channelCol);
    this.parsedLogEntries.getColumns().add(payloadCol);
}

From source file:de.perdian.apps.tagtiger.fx.handlers.batchupdate.UpdateFileNamesFromTagsActionEventHandler.java

private TableView<?> createNewFileNamesPane(ObservableList<UpdateFileNamesFromTagsItem> items) {

    TableColumn<UpdateFileNamesFromTagsItem, String> currentFileNameColumn = new TableColumn<>(
            this.getLocalization().currentFileName());
    currentFileNameColumn.setSortable(false);
    currentFileNameColumn.setCellValueFactory(p -> p.getValue().getCurrentFileName());
    TableColumn<UpdateFileNamesFromTagsItem, String> newFileNameColumn = new TableColumn<>(
            this.getLocalization().newFileName());
    newFileNameColumn.setSortable(false);
    newFileNameColumn.setCellValueFactory(p -> p.getValue().getNewFileName());

    TableView<UpdateFileNamesFromTagsItem> tableView = new TableView<>(items);
    tableView.getColumns().addAll(Arrays.asList(currentFileNameColumn, newFileNameColumn));
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    return tableView;

}

From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java

@FXML
void onShowCompoundIntensityTable(MouseEvent event) {
    if (tableCompound.getSelectionModel().isEmpty())
        return;//from   ww  w . j av a 2 s  .  com

    IntensityMatrixImpl intensityMatrix = dataManager.getIntensityMatrix();

    for (CompoundImpl compound : tableCompound.getSelectionModel().getSelectedItems()) {

        TableView<IntensityValue> tableView = new TableView<>(
                FXCollections
                        .observableArrayList(intensityMatrix
                                .getColumnKeys().stream().map(it -> new IntensityValue(it.getPlate(),
                                        it.getSample(), it, intensityMatrix.get(compound, it)))
                                .collect(Collectors.toList())));

        Arrays.asList("Plate", "Sample", "Injection", "Intensity").forEach(it -> {
            TableColumn<IntensityValue, Double> column = new TableColumn<>();
            column.setText(it);
            //noinspection unchecked
            column.setCellValueFactory(new PropertyValueFactory(it));
            tableView.getColumns().add(column);
        });

        Scene scene = new Scene(tableView);
        Stage stage = new Stage(StageStyle.UTILITY);
        stage.setScene(scene);
        stage.setWidth(800);
        stage.setHeight(600);
        stage.setTitle(compound.toString());
        stage.show();
    }

}