List of usage examples for javafx.scene.control TableView getColumns
public final ObservableList<TableColumn<S, ?>> getColumns()
From source file:Main.java
@Override public void start(Stage primaryStage) { TableView table = new TableView(); table.setEditable(true);//from ww w . j ava 2s .c om 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 w w . j av a2s . co m*/ 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: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 v a 2s. c om 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.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: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);/* w w w . j av a 2 s. c om*/ 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.ggvaidya.scinames.dataset.DatasetSceneController.java
public List<List<String>> getDataAsTable(TableView tv) { // What columns do we have? List<List<String>> result = new LinkedList<>(); List<TableColumn> columns = tv.getColumns(); columns.forEach(col -> {/*w w w . ja v a 2 s. co m*/ List<String> column = new LinkedList<>(); // Add the header. column.add(col.getText()); // Add the data. for (int x = 0; x < tv.getItems().size(); x++) { ObservableValue cellObservableValue = col.getCellObservableValue(x); column.add(cellObservableValue.getValue().toString()); } result.add(column); }); return result; }
From source file:fruitproject.FruitProject.java
public void second(final String pfname) { final Stage st = new Stage(); Scene scene = null;/*from w ww . j av a 2 s .com*/ final GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); TableView tv = new TableView(); final TableColumn<Map, String> firstDataColumn = new TableColumn<>("Name"); final TableColumn<Map, String> secondDataColumn = new TableColumn<>("Amount"); final TableColumn<Map, String> thirdDataColumn = new TableColumn<>("Remove"); firstDataColumn.setMinWidth(130); secondDataColumn.setMinWidth(130); thirdDataColumn.setMinWidth(130); if (!pfname.equals("")) { firstDataColumn.setCellValueFactory(new MapValueFactory(Column1MapKey)); secondDataColumn.setCellValueFactory(new MapValueFactory(Column2MapKey)); thirdDataColumn.setCellValueFactory(new MapValueFactory(Column3MapKey)); rows = 0; tv = new TableView<>(generateDataInMap(pfname, addPairs)); } tv.getColumns().setAll(firstDataColumn, secondDataColumn, thirdDataColumn); // secondDataColumn.setCellFactory(TextFieldTableCell.forTableColumn()); ScrollPane sp = new ScrollPane(); sp.setMinWidth(400); sp.setHbarPolicy(ScrollBarPolicy.NEVER); sp.setContent(tv); grid.add(sp, 0, 3); final ComboBox comboBox = new ComboBox(); HBox hb1 = new HBox(); comboBox.setValue("FILE"); comboBox.getItems().addAll("Save this file", "Load a new file"); Button btnOk = new Button(); btnOk.setText("OK"); hb1.getChildren().addAll(comboBox, btnOk); hb1.setSpacing(10); grid.add(hb1, 0, 1); Label label1 = new Label("Title:"); final TextField tfFilename = new TextField(); tfFilename.setText(getTitle(pfname)); HBox hb = new HBox(); hb.getChildren().addAll(label1, tfFilename); hb.setSpacing(10); grid.add(hb, 0, 2); final Stage ps = new Stage(); final TableView tv1 = tv; btnOk.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { //System.out.println("Hello World!"); if (comboBox.getValue().equals("Load a new file")) { first(ps); st.close(); } else { PrintWriter pw = null; try { pw = new PrintWriter("abc.json"); BufferedWriter bw = new BufferedWriter(new FileWriter(pfname, false)); bw.write("{title:\"" + tfFilename.getText() + "\""); bw.write(",fruits:["); for (int i = 0; i < rows; i++) { bw.write("{name:\"" + String.valueOf(firstDataColumn.getCellData(i)) + "\",amount:" + String.valueOf(secondDataColumn.getCellData(i)) + "}"); if (i != rows - 1) bw.write(","); } bw.write("]}"); bw.close(); } catch (Exception e) { System.out.println(e.toString()); } } } }); Button btn = new Button(); btn.setText("New Fruit"); grid.add(btn, 1, 2); // TableView tv=new TableView(); // TableColumn Col1 = new TableColumn("Name"); // TableColumn Col2 = new TableColumn("Amount"); // TableColumn Col3 = new TableColumn("Remove"); // tv.getColumns().addAll(Col1, Col2, Col3); //sp.setFitToWidth(true); Image img = new Image("file:music.jpg"); ImageView iv2 = new ImageView(); iv2.setImage(img); iv2.setFitWidth(200); iv2.setPreserveRatio(true); iv2.setSmooth(true); iv2.setCache(true); grid.add(iv2, 1, 3); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { //System.out.println("Hello World!"); System.out.println(comboBox.valueProperty()); st.close(); third(pfname); } }); scene = new Scene(grid, 700, 450); st.setScene(scene); st.show(); }
From source file:com.ggvaidya.scinames.model.Dataset.java
/** * Set up a TableView to contain the data contained in this dataset. * /*from ww w . ja v a 2 s . co m*/ * @param tv The TableView to populate. */ public void displayInTableView(TableView<DatasetRow> tv) { // Setup table. tv.setEditable(false); //controller.setTableColumnResizeProperty(TableView.CONSTRAINED_RESIZE_POLICY); ObservableList<TableColumn<DatasetRow, ?>> cols = tv.getColumns(); cols.clear(); // We need to precalculate. ObservableList<DatasetRow> rows = this.rowsProperty(); // Set up columns. TableColumn<DatasetRow, String> colRowName = new TableColumn<>("Name"); colRowName.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> { DatasetRow row = features.getValue(); Set<Name> names = getNamesInRow(row); if (names.isEmpty()) { return new ReadOnlyStringWrapper("(None)"); } else { return new ReadOnlyStringWrapper( names.stream().map(name -> name.getFullName()).collect(Collectors.joining("; "))); } }); colRowName.setPrefWidth(100.0); cols.add(colRowName); // Create a column for every column here. this.getColumns().forEach((DatasetColumn col) -> { String colName = col.getName(); TableColumn<DatasetRow, String> colColumn = new TableColumn<>(colName); colColumn.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> { DatasetRow row = features.getValue(); String val = row.get(colName); return new ReadOnlyStringWrapper(val == null ? "" : val); }); colColumn.setPrefWidth(100.0); cols.add(colColumn); }); // Set table items. // tv.getItems().clear(); tv.setItems(rows); }
From source file:com.ggvaidya.scinames.dataset.BinomialChangesSceneController.java
public List<List<String>> getDataAsTable(TableView tv) { // What columns do we have? List<List<String>> result = new LinkedList<>(); List<TableColumn> columns = tv.getColumns(); columns.forEach(col -> {//from w w w . jav a 2 s. c o m List<String> column = new LinkedList<>(); // Add the header. column.add(col.getText()); // Add the data. for (int x = 0; x < tv.getItems().size(); x++) { ObservableValue cellObservableValue = col.getCellObservableValue(x); Object val = (Object) cellObservableValue.getValue(); if (val == null) column.add(""); // or NA? else column.add(val.toString()); } result.add(column); }); return result; }
From source file:com.ggvaidya.scinames.dataset.DatasetSceneController.java
private void fillTableViewWithDatasetRows(TableView<DatasetRow> tableView) { // We need to precalculate. ObservableList<DatasetRow> rows = dataset.rowsProperty(); // Setup table. tableView.editableProperty().set(false); ObservableList<TableColumn<DatasetRow, ?>> cols = tableView.getColumns(); cols.clear();/*from ww w. jav a2 s. c o m*/ // Set up columns. TableColumn<DatasetRow, String> colRowName = new TableColumn<>("Name"); colRowName.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> { DatasetRow row = features.getValue(); Set<Name> names = dataset.getNamesInRow(row); if (names.isEmpty()) { return new ReadOnlyStringWrapper("(None)"); } else { return new ReadOnlyStringWrapper( names.stream().map(n -> n.getFullName()).collect(Collectors.joining("; "))); } }); colRowName.setPrefWidth(100.0); cols.add(colRowName); // Create a column for every column here. dataset.getColumns().forEach((DatasetColumn col) -> { String colName = col.getName(); TableColumn<DatasetRow, String> colColumn = new TableColumn<>(colName); colColumn.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> { DatasetRow row = features.getValue(); String val = row.get(colName); return new ReadOnlyStringWrapper(val == null ? "" : val); }); colColumn.setPrefWidth(100.0); cols.add(colColumn); }); // Set table items. tableView.itemsProperty().set(rows); // What if it's empty? tableView.setPlaceholder(new Label("No data contained in this dataset.")); }