下面列出了javafx.scene.control.TableColumn#getWidth ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void fillAvailableWidth() {
List<TableColumn<UITableItem<T>, ?>> columns = this.getControl().getColumns();
if(!columns.isEmpty()) {
Insets padding = getControl().getPadding();
double availableWidth = (this.getControl().getWidth() - (padding.getLeft() + padding.getRight() + VERTICAL_SCROLL_SIZE));
for(TableColumn<UITableItem<T>, ?> column : columns) {
availableWidth -= column.getWidth();
}
if( availableWidth > 0 ) {
TableColumn<UITableItem<T>, ?> lastColumn = columns.get(columns.size() - 1);
lastColumn.prefWidthProperty().set(lastColumn.getWidth() + availableWidth);
}
}
}
public void handleAttributeMoved(double sceneX, double sceneY) {
if (draggingAttributeNode != null) {
final Point2D location = sceneToLocal(sceneX, sceneY);
double x = location.getX() - draggingOffset.getX();
if (x < 0) {
x = 0;
}
if (x > RunPane.this.getWidth() - draggingAttributeNode.getWidth()) {
x = RunPane.this.getWidth() - draggingAttributeNode.getWidth();
}
double y = location.getY() - draggingOffset.getY();
if (y < 0) {
y = 0;
}
if (y > RunPane.this.getHeight() - draggingAttributeNode.getHeight()) {
y = RunPane.this.getHeight() - draggingAttributeNode.getHeight();
}
draggingAttributeNode.setLayoutX(x);
draggingAttributeNode.setLayoutY(y);
final Point2D tableLocation = sampleDataView.sceneToLocal(sceneX, sceneY);
double offset = 0;
Set<Node> nodes = sampleDataView.lookupAll(".scroll-bar");
for (final Node node : nodes) {
if (node instanceof ScrollBar) {
final ScrollBar scrollBar = (ScrollBar) node;
if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
offset = scrollBar.getValue();
break;
}
}
}
double totalWidth = 0;
mouseOverColumn = null;
final double cellPadding = 0.5; // ?
if (tableLocation.getX() >= 0 && tableLocation.getX() <= sampleDataView.getWidth() && tableLocation.getY() >= 0 && tableLocation.getY() <= sampleDataView.getHeight()) {
double columnLocation = tableLocation.getX() + offset;
for (TableColumn<TableRow, ?> column : sampleDataView.getColumns()) {
totalWidth += column.getWidth() + cellPadding;
if (columnLocation < totalWidth) {
mouseOverColumn = (ImportTableColumn) column;
break;
}
}
}
if (mouseOverColumn != null) {
// Allow for the SplitPane left side inset+padding (1+1 hard-coded).
final double edge = 2;
columnRectangle.setLayoutX(edge + sampleDataView.getLayoutX() + totalWidth - mouseOverColumn.getWidth() - offset);
columnRectangle.setLayoutY(sampleDataView.getLayoutY());
columnRectangle.setWidth(mouseOverColumn.getWidth());
columnRectangle.setHeight(sampleDataView.getHeight());
columnRectangle.setVisible(true);
} else {
columnRectangle.setVisible(false);
}
}
}
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());
};
}