Java Code Examples for javafx.scene.control.ScrollBar#getMax()

The following examples show how to use javafx.scene.control.ScrollBar#getMax() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScenarioConfigEditorFX.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
void scrolled(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
	double value = newValue.doubleValue();
	// System.out.println("Scrolled to " + value);
	ScrollBar bar = getVerticalScrollbar(tableView);
	if (value == bar.getMax()) {
		// System.out.println("Adding new persons.");
		// double targetValue = value * items.size();
		// addPersons();
		// bar.setValue(targetValue / items.size());
	}
}
 
Example 2
Source File: TableItemTask.java    From megan-ce with GNU General Public License v3.0 4 votes vote down vote up
private ListChangeListener<IMatchBlock> createChangeListener(final TableItem tableItem, final LongProperty previousSelectionTime) {
    final ReadLayoutPane pane = tableItem.getPane();
    return c -> {
        if (c.next()) {

            if (!pane.getMatchSelection().isEmpty())
                tableView.getSelectionModel().select(tableItem);
        }
        if (System.currentTimeMillis() - 200 > previousSelectionTime.get()) { // only if sufficient time has passed since last scroll...
            try {
                final double focusCoordinate;
                int focusIndex = pane.getMatchSelection().getFocusIndex();
                if (focusIndex >= 0 && pane.getMatchSelection().getItems()[focusIndex] != null) {
                    final IMatchBlock focusMatch = pane.getMatchSelection().getItems()[focusIndex];
                    focusCoordinate = 0.5 * (focusMatch.getAlignedQueryStart() + focusMatch.getAlignedQueryEnd());
                    double leadingWidth = 0;
                    double lastWidth = 0;
                    double totalWidth = 0;
                    {
                        int numberOfColumns = tableView.getColumns().size();
                        int columns = 0;
                        for (TableColumn col : tableView.getColumns()) {
                            if (col.isVisible()) {
                                if (columns < numberOfColumns - 1)
                                    leadingWidth += col.getWidth();
                                else
                                    lastWidth = col.getWidth();
                                totalWidth += col.getWidth();
                            }
                            columns++;
                        }
                    }

                    final double coordinateToShow = leadingWidth + lastWidth * (focusCoordinate / maxReadLength.get());
                    final ScrollBar hScrollBar = FXUtilities.findScrollBar(tableView, Orientation.HORIZONTAL);

                    if (hScrollBar != null) { // should never be null, but best to check...
                        final double newPos = (hScrollBar.getMax() - hScrollBar.getMin()) * ((coordinateToShow) / totalWidth);

                        Platform.runLater(() -> {
                            tableView.scrollTo(tableItem);
                            hScrollBar.setValue(newPos);
                        });
                    }
                }
            } catch (Exception ignored) {
            }
        }
        previousSelectionTime.set(System.currentTimeMillis());
    };
}