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() 

Source Link

Document

Creates a default TableView control with no content.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    TableView table = new TableView();
    table.setEditable(true);/*from www.j av a2 s  .c  o m*/

    TableColumn firstNameCol = new TableColumn("First Name");
    TableColumn lastNameCol = new TableColumn("Last Name");
    TableColumn emailCol = new TableColumn("Email");

    table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
    emailCol.setVisible(false);

    StackPane root = new StackPane();
    root.getChildren().add(table);
    primaryStage.setScene(new Scene(root, 200, 250));
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    TableView table = new TableView();
    table.setEditable(true);//from  w ww  . j  a  va  2  s . c om

    TableColumn firstNameCol = new TableColumn("First Name");
    TableColumn lastNameCol = new TableColumn("Last Name");
    TableColumn addressCol = new TableColumn("Email");

    table.getColumns().addAll(firstNameCol, lastNameCol, addressCol);

    TableColumn cityCol = new TableColumn("City");
    TableColumn stateCol = new TableColumn("State");

    addressCol.getColumns().addAll(cityCol, stateCol);

    StackPane root = new StackPane();
    root.getChildren().add(table);
    primaryStage.setScene(new Scene(root, 200, 250));
    primaryStage.show();
}

From source file:investor.views.CompaniesView.java

public void InitView() {
    selectedRange = DataRange.THREEMONTH;
    selectedChart = "line";
    pane = new VBox();
    lineChart = LinearChartManager.linear();
    lineChart.setTitle("");

    table = new TableView();

    try {/*from   w w  w.j  a  v  a  2 s. c  om*/
        table.getItems().addAll(NetworkManager.show(DataType.SPOL));
    } catch (Exception e) {
        System.out.println("Something went wrong when populating market indicisies view");
    }

    table.getColumns().addAll(initColumns());

    table.setRowFactory(tv -> {
        TableRow<Index> row = new TableRow<Index>();
        row.setOnMouseClicked(event -> {
            if (event.getClickCount() == 2 && (!row.isEmpty())) {
                Index rowData = row.getItem();
                selectedIndex = rowData;
                //System.out.println(rowData);
                try {
                    lastData = NetworkManager.showMore(rowData.getSymbol(), selectedRange);
                    System.out.println(lastData.length);

                    if (selectedChart.equals("line")) {
                        lineChart.getData().clear();
                        lineChart.setTitle(rowData.getName());
                        LinearChartManager.addSeries(lineChart, lastData, selectedRange);
                        if (pointerType != null && pointerType != "hide") {
                            OnPointerChange();
                        }
                    } else {
                        CandleChart.generateData(lastData);
                        candleChart = new CandleChart();
                        CandleChart.CandleStickChart chart = candleChart.createChart();
                        chart.setTitle(rowData.getName());
                        pane.getStylesheets().add("resources/css/CandleStickChart.css");
                        borderPane.setCenter(chart);
                    }
                } catch (Exception ex) {
                    System.out.println("Error while downloading indicise " + ex.toString());
                }
            }
        });
        return row;
    });

    //table.setItems(initRows());
    table.setEditable(false);

    VBox vBox = (VBox) pane;

    borderPane = new BorderPane();
    borderPane.setCenter(lineChart);
    borderPane.setRight(addMenuButtons());

    vBox.getChildren().add(table);
    vBox.getChildren().add(borderPane);
}

From source file:investor.views.MarketIndicisesView.java

public void InitView() {
    pane = new VBox();

    //Stworzenie wykresu
    lineChart = LinearChartManager.linear();
    lineChart.setTitle("");

    //Poczatkowo zakres dat to 3M
    selectedRange = DataRange.THREEMONTH;

    selectedChart = "line";
    //Stworzenie tabelki
    table = new TableView();

    //Scigamy dane dla tabelki z serwera i populujemy tabelke
    try {/*from w  w  w . j  a v a2s. co  m*/
        table.getItems().addAll(NetworkManager.show(DataType.WSK));
    } catch (Exception e) {
        System.out.println("Something went wrong when populating market indicisies view");
    }

    //Dodajemy kolumny do tabelki
    table.getColumns().addAll(initColumns());

    //Obsuga kliknicia wiersza w tabelce
    table.setRowFactory(tv -> {
        TableRow<Index> row = new TableRow<Index>();
        row.setOnMouseClicked(event -> {
            if (event.getClickCount() == 2 && (!row.isEmpty())) {

                //Zapamitujemy wybrany wiersz dla widoku
                Index rowData = row.getItem();
                selectedIndex = rowData;
                //System.out.println(rowData);
                try {

                    //Scigamy dane z serwera dla danego wiersza i dodajemy je do wykresu
                    lastData = NetworkManager.showMore(rowData.getSymbol(), selectedRange);
                    System.out.println(lastData.length);

                    if (selectedChart.equals("line")) {
                        lineChart.getData().clear();
                        LinearChartManager.addSeries(lineChart, lastData, selectedRange);
                        lineChart.setTitle(rowData.getName());
                        if (pointerType != null && pointerType != "hide") {
                            OnPointerChange();
                        }
                    } else {
                        CandleChart.generateData(lastData);
                        candleChart = new CandleChart();
                        CandleChart.CandleStickChart chart = candleChart.createChart();
                        chart.setTitle(rowData.getName());
                        pane.getStylesheets().add("resources/css/CandleStickChart.css");
                        borderPane.setCenter(chart);
                    }
                } catch (Exception ex) {
                    System.out.println("Error while downloading indicise " + ex.toString());
                }
            }
        });
        return row;
    });

    //table.setItems(initRows());
    table.setEditable(false);

    VBox vBox = (VBox) pane;

    //Panel dla wykresu i przyciskw konfiguracyjnych
    borderPane = new BorderPane();

    //Po rodku wykres
    borderPane.setCenter(lineChart);

    //Na prawo przyciski konfiguracyjne
    borderPane.setRight(addMenuButtons());

    //Dodanie do panelu widoku tabelki
    vBox.getChildren().add(table);

    //Dodanie do panelu widoku panelu z wykresem i przyciskami konfiguracyjnymi
    vBox.getChildren().add(borderPane);
}

From source file:com.bdb.weather.display.windrose.WindRosePane.java

/**
 * Constructor.//ww w. j  a v a  2s . c  o m
 */
public WindRosePane() {
    this.setPrefSize(300, 300);
    ChartFactory.getChartTheme().apply(chart);
    chartViewer.setMinHeight(10);
    chartViewer.setMinWidth(10);
    chartViewer.setPrefSize(300, 300);

    dataTable = new TableView();

    FlowPane summaryPanel = new FlowPane();

    summaryPanel.getChildren().add(new LabeledFieldPane<>("Date:", timeField));
    timeField.setEditable(false);
    summaryPanel.getChildren().add(new LabeledFieldPane<>("% Winds are calm:", calmField));
    calmField.setEditable(false);

    summaryPanel.getChildren().add(new Label("Speeds are in " + Speed.getDefaultUnit()));

    BorderPane p = new BorderPane();

    p.setCenter(dataTable);
    p.setTop(summaryPanel);
    this.setTabContents(chartViewer, p);

    TableColumn<WindSlice, String> headingColumn = new TableColumn<>("Heading");
    headingColumn.setCellValueFactory((rec) -> new ReadOnlyStringWrapper(
            Heading.headingForSlice(rec.getValue().getHeadingIndex(), 16).getCompassLabel()));
    dataTable.getColumns().add(headingColumn);

    TableColumn<WindSlice, String> percentOfWindColumn = new TableColumn<>("% of Wind");
    percentOfWindColumn.setCellValueFactory(
            (rec) -> new ReadOnlyStringWrapper(String.format("%.1f", rec.getValue().getPercentageOfWind())));
    dataTable.getColumns().add(percentOfWindColumn);

    TableColumn<WindSlice, Speed> avgSpeedColumn = new TableColumn<>("Avg Speed");
    avgSpeedColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper<>(rec.getValue().getAvgSpeed()));
    dataTable.getColumns().add(avgSpeedColumn);

    TableColumn<WindSlice, Speed> maxSpeedColumn = new TableColumn<>("Max Speed");
    maxSpeedColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper<>(rec.getValue().getMaxSpeed()));
    dataTable.getColumns().add(maxSpeedColumn);

}

From source file:Main.java

private TableView<Person> createEmployeeTableView(ObservableList<Person> teamMembers) {
    final TableView<Person> employeeTableView = new TableView<>();
    employeeTableView.setPrefWidth(300);

    employeeTableView.setItems(teamMembers);

    TableColumn<Person, String> aliasNameCol = new TableColumn<>("Alias");
    TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
    TableColumn<Person, String> lastNameCol = new TableColumn<>("Last Name");

    aliasNameCol.setEditable(true);//from  w w  w  .j a va  2s . co m

    aliasNameCol.setPrefWidth(employeeTableView.getPrefWidth() / 3);
    firstNameCol.setPrefWidth(employeeTableView.getPrefWidth() / 3);
    lastNameCol.setPrefWidth(employeeTableView.getPrefWidth() / 3);

    aliasNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("aliasName"));
    firstNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
    lastNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));

    employeeTableView.getColumns().setAll(aliasNameCol, firstNameCol, lastNameCol);

    return employeeTableView;
}

From source file:com.bdb.weather.display.summary.RainSummary.java

@SuppressWarnings("LeakingThisInConstructor")
public RainSummary(SummaryInterval interval, SummarySupporter supporter) {
    this.setPrefSize(500, 300);
    this.interval = interval;
    this.supporter = supporter;
    dataTable = new TableView();
    Node component = createChartElements();

    TableColumn<SummaryRecord, String> col = new TableColumn<>("Date");
    col.setCellValueFactory(// w  w w . ja  v  a 2s.  c o  m
            (rec) -> new ReadOnlyStringWrapper(DisplayConstants.formatDate(rec.getValue().getDate())));
    dataTable.getColumns().add(col);

    TableColumn<SummaryRecord, Depth> rainfallColumn = new TableColumn<>("Rainfall");
    rainfallColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper(rec.getValue().getTotalRainfall()));
    dataTable.getColumns().add(rainfallColumn);

    TableColumn<SummaryRecord, Depth> etColumn = new TableColumn<>("ET");
    etColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper(rec.getValue().getTotalET()));
    dataTable.getColumns().add(etColumn);

    this.setTabContents(component, dataTable);
}

From source file:com.bdb.weather.display.day.DayXYPlotPane.java

protected final void createElements() {
    createChartElements();/*from  w  ww . java 2  s  .  co  m*/

    //
    // Build the table for the data tab
    //
    dataTable = new TableView<>();

    this.setTabContents(chartViewer, dataTable);

    TableColumn<HistoricalRecord, String> col = new TableColumn<>(TIME_HEADING);
    col.setCellValueFactory((rec) -> new ReadOnlyStringWrapper(
            DisplayConstants.formatTime(rec.getValue().getTime().toLocalTime())));
    dataTable.getColumns().add(col);

    doConfigure(displayMenu);
    this.layout();
}

From source file:com.bdb.weather.display.summary.WindSummary.java

/**
 * Create the table.//from   w ww.j a  va 2s  .c  o  m
 * 
 * @return The JavaFX Node
 */
private Node createTable() {
    dataTable = new TableView();

    TableColumn<SummaryRecord, String> col = new TableColumn<>("Date");
    col.setCellValueFactory(
            (rec) -> new ReadOnlyStringWrapper(DisplayConstants.formatDate(rec.getValue().getDate())));
    dataTable.getColumns().add(col);

    TableColumn<SummaryRecord, Speed> avgWindColumn = new TableColumn<>("Avg Wind");
    avgWindColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper(rec.getValue().getAvgWindSpeed()));
    dataTable.getColumns().add(avgWindColumn);

    TableColumn<SummaryRecord, Depth> maxWindColumn = new TableColumn<>("Max Wind");
    maxWindColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper(rec.getValue().getMaxWindSpeed()));
    dataTable.getColumns().add(maxWindColumn);

    TableColumn<SummaryRecord, Depth> maxGustColumn = new TableColumn<>("Max Wind");
    maxGustColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper(rec.getValue().getMaxWindGust()));
    dataTable.getColumns().add(maxGustColumn);

    return dataTable;
}

From source file:net.sourceforge.msscodefactory.cfbam.v2_7.CFBamJavaFX.CFBamJavaFXScopePickerPane.java

public CFBamJavaFXScopePickerPane(ICFFormManager formManager, ICFBamJavaFXSchema argSchema,
        ICFBamScopeObj argFocus, ICFLibAnyObj argContainer, Collection<ICFBamScopeObj> argDataCollection,
        ICFBamJavaFXScopeChosen whenChosen) {
    super();/*from  w w  w  .  j a va 2 s.  c om*/
    final String S_ProcName = "construct-schema-focus";
    if (formManager == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                "formManager");
    }
    cfFormManager = formManager;
    if (argSchema == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 2,
                "argSchema");
    }
    if (whenChosen == null) {
        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 6,
                "whenChosen");
    }
    invokeWhenChosen = whenChosen;
    // argFocus is optional; focus may be set later during execution as
    // conditions of the runtime change.
    javafxSchema = argSchema;
    javaFXFocus = argFocus;
    javafxContainer = argContainer;
    setJavaFXDataCollection(argDataCollection);
    dataTable = new TableView<ICFBamScopeObj>();
    tableColumnObjKind = new TableColumn<ICFBamScopeObj, String>("Class Code");
    tableColumnObjKind.setCellValueFactory(
            new Callback<CellDataFeatures<ICFBamScopeObj, String>, ObservableValue<String>>() {
                @Override
                public ObservableValue<String> call(CellDataFeatures<ICFBamScopeObj, String> p) {
                    ICFBamScopeObj obj = p.getValue();
                    if (obj == null) {
                        return (null);
                    } else {
                        String classCode = obj.getClassCode();
                        ReadOnlyObjectWrapper<String> observable = new ReadOnlyObjectWrapper<String>();
                        observable.setValue(classCode);
                        return (observable);
                    }
                }
            });
    tableColumnObjKind.setCellFactory(
            new Callback<TableColumn<ICFBamScopeObj, String>, TableCell<ICFBamScopeObj, String>>() {
                @Override
                public TableCell<ICFBamScopeObj, String> call(TableColumn<ICFBamScopeObj, String> arg) {
                    return new CFStringTableCell<ICFBamScopeObj>();
                }
            });
    dataTable.getColumns().add(tableColumnObjKind);
    tableColumnId = new TableColumn<ICFBamScopeObj, Long>("Id");
    tableColumnId
            .setCellValueFactory(new Callback<CellDataFeatures<ICFBamScopeObj, Long>, ObservableValue<Long>>() {
                public ObservableValue<Long> call(CellDataFeatures<ICFBamScopeObj, Long> p) {
                    ICFBamScopeObj obj = p.getValue();
                    if (obj == null) {
                        return (null);
                    } else {
                        long value = obj.getRequiredId();
                        Long wrapped = new Long(value);
                        ReadOnlyObjectWrapper<Long> observable = new ReadOnlyObjectWrapper<Long>();
                        observable.setValue(wrapped);
                        return (observable);
                    }
                }
            });
    tableColumnId
            .setCellFactory(new Callback<TableColumn<ICFBamScopeObj, Long>, TableCell<ICFBamScopeObj, Long>>() {
                @Override
                public TableCell<ICFBamScopeObj, Long> call(TableColumn<ICFBamScopeObj, Long> arg) {
                    return new CFInt64TableCell<ICFBamScopeObj>();
                }
            });
    dataTable.getColumns().add(tableColumnId);
    dataTable.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<ICFBamScopeObj>() {
        @Override
        public void changed(ObservableValue<? extends ICFBamScopeObj> observable, ICFBamScopeObj oldValue,
                ICFBamScopeObj newValue) {
            setJavaFXFocus(newValue);
            if (buttonChooseSelected != null) {
                if (newValue != null) {
                    buttonChooseSelected.setDisable(false);
                } else {
                    buttonChooseSelected.setDisable(true);
                }
            }
        }
    });
    hboxMenu = new CFHBox(10);
    buttonCancel = new CFButton();
    buttonCancel.setMinWidth(200);
    buttonCancel.setText("Cancel");
    buttonCancel.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            final String S_ProcName = "handle";
            try {
                cfFormManager.closeCurrentForm();
            } catch (Throwable t) {
                CFConsole.formException(S_FormName, ((CFButton) e.getSource()).getText(), t);
            }
        }
    });
    hboxMenu.getChildren().add(buttonCancel);
    buttonChooseNone = new CFButton();
    buttonChooseNone.setMinWidth(200);
    buttonChooseNone.setText("ChooseNone");
    buttonChooseNone.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            final String S_ProcName = "handle";
            try {
                ICFBamSchemaObj schemaObj = (ICFBamSchemaObj) javafxSchema.getSchema();
                if (schemaObj == null) {
                    throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                            "schemaObj");
                }
                invokeWhenChosen.choseScope(null);
                cfFormManager.closeCurrentForm();
            } catch (Throwable t) {
                CFConsole.formException(S_FormName, ((CFButton) e.getSource()).getText(), t);
            }
        }
    });
    hboxMenu.getChildren().add(buttonChooseNone);
    buttonChooseSelected = new CFButton();
    buttonChooseSelected.setMinWidth(200);
    buttonChooseSelected.setText("ChooseSelected");
    buttonChooseSelected.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            final String S_ProcName = "handle";
            try {
                ICFBamSchemaObj schemaObj = (ICFBamSchemaObj) javafxSchema.getSchema();
                if (schemaObj == null) {
                    throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                            "schemaObj");
                }
                ICFBamScopeObj selectedInstance = getJavaFXFocusAsScope();
                invokeWhenChosen.choseScope(selectedInstance);
                cfFormManager.closeCurrentForm();
            } catch (Throwable t) {
                CFConsole.formException(S_FormName, ((CFButton) e.getSource()).getText(), t);
            }
        }
    });
    hboxMenu.getChildren().add(buttonChooseSelected);
    if (argFocus != null) {
        dataTable.getSelectionModel().select(argFocus);
    }
    setTop(hboxMenu);
    setCenter(dataTable);
}