Search in sources :

Example 31 with TableColumn

use of javafx.scene.control.TableColumn in project Gargoyle by callakrsos.

the class CheckBoxTableCellExam method start.

/*
	 * (non-Javadoc)
	 *
	 * @see javafx.application.Application#start(javafx.stage.Stage)
	 */
@Override
public void start(Stage primaryStage) throws Exception {
    TableView<SampleVO> center = new TableView<>();
    center.setEditable(true);
    TableColumn<SampleVO, Boolean> e = new TableColumn<SampleVO, Boolean>();
    e.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<SampleVO, Boolean>, ObservableValue<Boolean>>() {

        @Override
        public ObservableValue<Boolean> call(CellDataFeatures<SampleVO, Boolean> param) {
            return param.getValue().checked;
        }
    });
    e.setCellFactory(new Callback<TableColumn<SampleVO, Boolean>, TableCell<SampleVO, Boolean>>() {

        @Override
        public TableCell<SampleVO, Boolean> call(TableColumn<SampleVO, Boolean> param) {
            return new CheckBoxTableCell<SampleVO, Boolean>() {

                /*
					 * (non-Javadoc)
					 *
					 * @see
					 * javafx.scene.control.cell.CheckBoxTableCell#updateItem(
					 * java.lang.Object, boolean)
					 */
                @Override
                public void updateItem(Boolean item, boolean empty) {
                    super.updateItem(item, empty);
                }

                /*
					 * (non-Javadoc)
					 *
					 * @see
					 * javafx.scene.control.Cell#isItemChanged(java.lang.Object,
					 * java.lang.Object)
					 */
                @Override
                protected boolean isItemChanged(Boolean oldItem, Boolean newItem) {
                    System.out.println(oldItem + " : " + newItem);
                    return super.isItemChanged(oldItem, newItem);
                }
            };
        }
    });
    e.setEditable(true);
    TableColumn<SampleVO, String> e2 = new TableColumn<SampleVO, String>();
    e2.setCellValueFactory(new PropertyValueFactory<SampleVO, String>("name"));
    center.getColumns().add(e);
    center.getColumns().add(e2);
    center.getItems().add(new SampleVO(true, "kim"));
    center.getItems().add(new SampleVO(true, "young"));
    BorderPane borderPane = new BorderPane(center);
    primaryStage.setScene(new Scene(borderPane));
    primaryStage.show();
}
Also used : BorderPane(javafx.scene.layout.BorderPane) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) ObservableValue(javafx.beans.value.ObservableValue) Scene(javafx.scene.Scene) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) SampleVO(com.kyj.fx.voeditor.visual.example.CheckBoxTableCellExam.SampleVO) TableView(javafx.scene.control.TableView)

Example 32 with TableColumn

use of javafx.scene.control.TableColumn in project Gargoyle by callakrsos.

the class FilterTableExample method start.

@Override
public void start(Stage primaryStage) throws Exception {
    TableView<DataItem> tableView = new TableView<>();
    FxUtil.installClipboardKeyEvent(tableView);
    tableView.setItems(FXCollections.observableArrayList());
    IntStream.range(0, 20000).mapToObj(i -> new DataItem()).forEach(d -> tableView.getItems().add(d));
    TableColumn<DataItem, Integer> smallInt = new TableColumn<>("Small Int");
    smallInt.setCellValueFactory(cb -> new ReadOnlyObjectWrapper<>(cb.getValue().getSmallIntValue()));
    TableColumn<DataItem, Integer> largeInt = new TableColumn<>("Large Int");
    largeInt.setCellValueFactory(cb -> new ReadOnlyObjectWrapper<>(cb.getValue().getLargeIntValue()));
    TableColumn<DataItem, String> randomLetter = new TableColumn<>("Letter");
    randomLetter.setCellValueFactory(cb -> new ReadOnlyObjectWrapper<>(cb.getValue().getRandomLetter()));
    TableColumn<DataItem, String> randomString1 = new TableColumn<>("AlphaNum 1");
    randomString1.setCellValueFactory(cb -> new ReadOnlyObjectWrapper<>(cb.getValue().getRandomStr1()));
    TableColumn<DataItem, String> randomString2 = new TableColumn<>("AlphaNum 2");
    randomString1.setCellValueFactory(cb -> new ReadOnlyObjectWrapper<>(cb.getValue().getRandomStr2()));
    tableView.getColumns().addAll(smallInt, largeInt, randomLetter, randomString1, randomString2);
    Platform.runLater(() -> new TableFilter<>(tableView));
    GridPane grp = new GridPane();
    GridPane.setFillHeight(tableView, true);
    GridPane.setFillWidth(tableView, true);
    GridPane.setHgrow(tableView, Priority.ALWAYS);
    GridPane.setVgrow(tableView, Priority.ALWAYS);
    grp.getChildren().add(tableView);
    Scene scene = new Scene(grp);
    primaryStage.setScene(scene);
    primaryStage.show();
}
Also used : IntStream(java.util.stream.IntStream) Scene(javafx.scene.Scene) FXCollections(javafx.collections.FXCollections) Random(java.util.Random) UUID(java.util.UUID) TableColumn(javafx.scene.control.TableColumn) Application(javafx.application.Application) Platform(javafx.application.Platform) Priority(javafx.scene.layout.Priority) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) Stage(javafx.stage.Stage) TableFilter(org.controlsfx.control.table.TableFilter) TableView(javafx.scene.control.TableView) GridPane(javafx.scene.layout.GridPane) GridPane(javafx.scene.layout.GridPane) Scene(javafx.scene.Scene) TableColumn(javafx.scene.control.TableColumn) TableView(javafx.scene.control.TableView)

Example 33 with TableColumn

use of javafx.scene.control.TableColumn in project Gargoyle by callakrsos.

the class ClipboardKeyEventInstaller method install.

/********************************
	 * 작성일 :  2016. 9. 3. 작성자 : KYJ
	 *
	 *
	 * @param tb
	 ********************************/
public static void install(TableView<?> tb) {
    tb.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
        int type = -1;
        if (e.isControlDown() && e.getCode() == KeyCode.C) {
            if (e.isShiftDown()) {
                type = 2;
            } else {
                type = 1;
            }
            if (type == -1)
                return;
            ObservableList<TablePosition> selectedCells = tb.getSelectionModel().getSelectedCells();
            TablePosition tablePosition = selectedCells.get(0);
            TableColumn tableColumn = tablePosition.getTableColumn();
            int row = tablePosition.getRow();
            int col = tb.getColumns().indexOf(tableColumn);
            switch(type) {
                case 1:
                    StringBuilder sb = new StringBuilder();
                    for (TablePosition cell : selectedCells) {
                        if (row != cell.getRow()) {
                            sb.append("\n");
                            row++;
                        } else if (col != tb.getColumns().indexOf(cell.getTableColumn())) {
                            sb.append("\t");
                        }
                        Object cellData = getDisplayText(cell, row);
                        sb.append(ValueUtil.decode(cellData, cellData, "").toString());
                    }
                    FxClipboardUtil.putString(sb.toString());
                    break;
                case 2:
                    Object cellData = getDisplayText(tableColumn, row);
                    FxClipboardUtil.putString(ValueUtil.decode(cellData, cellData, "").toString());
                    break;
            }
            e.consume();
        }
    });
}
Also used : TablePosition(javafx.scene.control.TablePosition) TableColumn(javafx.scene.control.TableColumn)

Example 34 with TableColumn

use of javafx.scene.control.TableColumn in project Gargoyle by callakrsos.

the class TableViewWithVisibleRowCountExam method start.

/* (non-Javadoc)
	 * @see javafx.application.Application#start(javafx.stage.Stage)
	 */
@Override
public void start(Stage primaryStage) throws Exception {
    TableViewWithVisibleRowCount<Object> center = new TableViewWithVisibleRowCount<>();
    TableColumn<Object, Object> e = new TableColumn<>();
    e.setCellValueFactory(new PropertyValueFactory<>("name"));
    center.getColumns().add(e);
    center.getItems().add(new Person("ssss"));
    center.getItems().add(new Person("ssss"));
    center.getItems().add(new Person("ssss"));
    center.getItems().add(new Person("ssss"));
    center.getItems().add(new Person("ssss"));
    center.getItems().add(new Person("ssss"));
    primaryStage.setScene(new Scene(new BorderPane(center), 300, 400));
    primaryStage.show();
    Platform.runLater(() -> {
        System.out.println(center.getVisibleRowCount());
    });
}
Also used : BorderPane(javafx.scene.layout.BorderPane) Scene(javafx.scene.Scene) TableColumn(javafx.scene.control.TableColumn)

Example 35 with TableColumn

use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.

the class ReconcileDialogController method configureTableView.

private void configureTableView(final TableView<RecTransaction> tableView, final TableViewManager<RecTransaction> tableViewManager) {
    tableView.setTableMenuButtonVisible(false);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    final TableColumn<RecTransaction, String> reconciledColumn = new TableColumn<>(resources.getString("Column.Clr"));
    reconciledColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getReconciledState().toString()));
    tableView.getColumns().add(reconciledColumn);
    final TableColumn<RecTransaction, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
    dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDate()));
    dateColumn.setCellFactory(param -> new ShortDateTableCell<>());
    tableView.getColumns().add(dateColumn);
    final TableColumn<RecTransaction, String> numberColumn = new TableColumn<>(resources.getString("Column.Num"));
    numberColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getNumber()));
    tableView.getColumns().add(numberColumn);
    final TableColumn<RecTransaction, String> payeeColumn = new TableColumn<>(resources.getString("Column.Payee"));
    payeeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPayee()));
    tableView.getColumns().add(payeeColumn);
    final TableColumn<RecTransaction, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
    amountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(AccountBalanceDisplayManager.convertToSelectedBalanceMode(account.getAccountType(), param.getValue().getAmount(account))));
    amountColumn.setCellFactory(param -> new BigDecimalTableCell<>(CommodityFormat.getShortNumberFormat(account.getCurrencyNode())));
    tableView.getColumns().add(amountColumn);
    // hide the horizontal scrollbar
    tableView.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS);
    tableViewManager.setColumnFormatFactory(param -> {
        if (param == amountColumn && account != null) {
            return CommodityFormat.getShortNumberFormat(account.getCurrencyNode());
        }
        return null;
    });
    final ChangeListener<Number> widthListener = new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            if (newValue != null && newValue.doubleValue() > 0) {
                JavaFXUtils.runLater(tableViewManager::restoreLayout);
                JavaFXUtils.runLater(tableViewManager::packTable);
                tableView.widthProperty().removeListener(this);
            }
        }
    };
    tableView.widthProperty().addListener(widthListener);
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) RecTransaction(jgnash.engine.RecTransaction) ChangeListener(javafx.beans.value.ChangeListener)

Aggregations

TableColumn (javafx.scene.control.TableColumn)40 TableView (javafx.scene.control.TableView)13 BigDecimal (java.math.BigDecimal)11 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)10 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)9 LocalDate (java.time.LocalDate)8 Map (java.util.Map)8 Scene (javafx.scene.Scene)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 BorderPane (javafx.scene.layout.BorderPane)7 List (java.util.List)6 FXML (javafx.fxml.FXML)5 TableCell (javafx.scene.control.TableCell)5 ObjectProperty (javafx.beans.property.ObjectProperty)4 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)4 ObservableValue (javafx.beans.value.ObservableValue)4 ObservableList (javafx.collections.ObservableList)4 Button (javafx.scene.control.Button)4 SelectionMode (javafx.scene.control.SelectionMode)4