use of javafx.scene.control.ScrollBar in project jgnash by ccavanaugh.
the class BudgetTableController method initialize.
@FXML
private void initialize() {
final Preferences preferences = Preferences.userNodeForPackage(BudgetTableController.class);
runningTotalsButton.selectedProperty().setValue(preferences.getBoolean(RUNNING_TOTALS, false));
rateLimitExecutor = new ScheduledThreadPoolExecutor(1, new DefaultDaemonThreadFactory(), new ThreadPoolExecutor.DiscardPolicy());
tableWidthChangeListener = (observable, oldValue, newValue) -> {
if (newValue != null && !oldValue.equals(newValue)) {
optimizeColumnWidths();
}
};
updateHeights();
yearSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(LocalDate.now().getYear() - YEAR_MARGIN, LocalDate.now().getYear() + YEAR_MARGIN, LocalDate.now().getYear(), 1));
accountTreeView.getStylesheets().addAll(StyleClass.HIDE_VERTICAL_CSS);
accountTreeView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
accountTreeView.setShowRoot(false);
accountTreeView.setEditable(true);
accountTreeView.fixedCellSizeProperty().bind(rowHeight);
accountSummaryTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
accountSummaryTable.getStylesheets().addAll(StyleClass.HIDE_VERTICAL_CSS, StyleClass.HIDE_HORIZONTAL_CSS);
accountSummaryTable.setItems(expandedAccountList);
accountSummaryTable.fixedCellSizeProperty().bind(rowHeight);
accountSummaryTable.setSelectionModel(new NullTableViewSelectionModel<>(accountSummaryTable));
accountTypeTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
accountTypeTable.getStylesheets().add(StyleClass.HIDE_HEADER_CSS);
accountTypeTable.setItems(accountGroupList);
accountTypeTable.fixedCellSizeProperty().bind(rowHeight);
accountTypeTable.prefHeightProperty().bind(rowHeight.multiply(Bindings.size(accountGroupList)).add(BORDER_MARGIN));
accountTypeTable.setSelectionModel(new NullTableViewSelectionModel<>(accountTypeTable));
accountGroupPeriodSummaryTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
accountGroupPeriodSummaryTable.getStylesheets().addAll(StyleClass.HIDE_HEADER_CSS, StyleClass.HIDE_HORIZONTAL_CSS, StyleClass.HIDE_VERTICAL_CSS);
accountGroupPeriodSummaryTable.setItems(accountGroupList);
accountGroupPeriodSummaryTable.fixedCellSizeProperty().bind(rowHeight);
accountGroupPeriodSummaryTable.prefHeightProperty().bind(rowHeight.multiply(Bindings.size(accountGroupList)).add(BORDER_MARGIN));
accountGroupPeriodSummaryTable.setSelectionModel(new NullTableViewSelectionModel<>(accountGroupPeriodSummaryTable));
buildAccountTreeTable();
buildAccountTypeTable();
buildAccountSummaryTable();
buildAccountGroupSummaryTable();
accountSummaryTable.maxWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountGroupPeriodSummaryTable.maxWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountSummaryTable.minWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountGroupPeriodSummaryTable.minWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountTreeView.expandedItemCountProperty().addListener((observable, oldValue, newValue) -> JavaFXUtils.runLater(this::updateExpandedAccountList));
final ChangeListener<Object> budgetChangeListener = (observable, oldValue, newValue) -> handleBudgetChange();
budget.addListener(budgetChangeListener);
yearSpinner.valueProperty().addListener(budgetChangeListener);
runningTotalsButton.selectedProperty().addListener(budgetChangeListener);
visibleColumnCount.addListener(budgetChangeListener);
runningTotalsButton.selectedProperty().addListener((observable, oldValue, newValue) -> preferences.putBoolean(RUNNING_TOTALS, newValue));
/* Setting the tables as un-managed effectively removes these tables from the GridPane. The tables are
redundant if showing the amounts as running balances. */
accountSummaryTable.managedProperty().bind(runningTotalsButton.selectedProperty().not());
accountGroupPeriodSummaryTable.managedProperty().bind(runningTotalsButton.selectedProperty().not());
horizontalScrollBar.setMin(0);
horizontalScrollBar.maxProperty().bind(periodCount.subtract(visibleColumnCount));
horizontalScrollBar.setUnitIncrement(1);
horizontalScrollBar.disableProperty().bind(periodCount.lessThanOrEqualTo(1));
// shift the table right and left with the ScrollBar value
horizontalScrollBar.valueProperty().addListener((observable, oldValue, newValue) -> {
/* must be synchronized to prevent a race condition from multiple events and an out of
* bounds exception */
synchronized (this) {
/* don't try unless columns exist. This can occur if the UI is not large enough to display
* a minimum of one period of information.
*/
if (periodTable.getColumns().size() > 0) {
final int newIndex = (int) Math.round(newValue.doubleValue());
if (newIndex > index) {
while (newIndex > index) {
handleShiftRight();
}
} else if (newIndex < index) {
while (newIndex < index) {
handleShiftLeft();
}
}
}
}
});
ThemeManager.fontScaleProperty().addListener((observable, oldValue, newValue) -> updateHeights());
}
use of javafx.scene.control.ScrollBar in project mastering-java by Kingminghuang.
the class MultipleBounceBall method start.
@Override
public void start(Stage primaryStage) throws Exception {
MultipleBallPane ballPane = new MultipleBallPane();
ballPane.setStyle("-fx-border-color: red");
Button addBtn = new Button("+");
Button subtractBtn = new Button("-");
HBox hBox = new HBox(10);
hBox.getChildren().addAll(addBtn, subtractBtn);
hBox.setAlignment(Pos.CENTER);
addBtn.setOnAction(event -> ballPane.add());
subtractBtn.setOnAction(event -> ballPane.subtract());
ballPane.setOnMousePressed(event -> ballPane.pause());
ballPane.setOnMouseReleased(event -> ballPane.play());
ScrollBar speedCtrl = new ScrollBar();
speedCtrl.setMax(50);
speedCtrl.setValue(25);
ballPane.rateProperty().bind(speedCtrl.valueProperty());
BorderPane borderPane = new BorderPane();
borderPane.setCenter(ballPane);
borderPane.setTop(speedCtrl);
borderPane.setBottom(hBox);
Scene scene = new Scene(borderPane, DEFAULT_WIDTH, DEFAULT_HEIGHT);
primaryStage.setTitle("Multiple Bounce Ball");
primaryStage.setScene(scene);
primaryStage.show();
}
Aggregations