本文整理汇总了Java中javafx.scene.layout.Region.setPrefSize方法的典型用法代码示例。如果您正苦于以下问题:Java Region.setPrefSize方法的具体用法?Java Region.setPrefSize怎么用?Java Region.setPrefSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.layout.Region
的用法示例。
在下文中一共展示了Region.setPrefSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import javafx.scene.layout.Region; //导入方法依赖的package包/类
@Override
public void start(Stage primaryStage) throws MalformedURLException {
Region zoomTarget = createContent();
zoomTarget.setPrefSize(1000, 1000);
zoomTarget.setOnDragDetected(evt -> {
Node target = (Node) evt.getTarget();
while (target != zoomTarget && target != null) {
target = target.getParent();
}
if (target != null) {
target.startFullDrag();
}
});
Group group = new Group(zoomTarget);
// stackpane for centering the content, in case the ScrollPane viewport
// is larget than zoomTarget
StackPane content = new StackPane(group);
group.layoutBoundsProperty().addListener((observable, oldBounds, newBounds) -> {
// keep it at least as large as the content
content.setMinWidth(newBounds.getWidth());
content.setMinHeight(newBounds.getHeight());
});
ScrollPane scrollPane = new ScrollPane(content);
scrollPane.setPannable(true);
scrollPane.viewportBoundsProperty().addListener((observable, oldBounds, newBounds) -> {
// use vieport size, if not too small for zoomTarget
content.setPrefSize(newBounds.getWidth(), newBounds.getHeight());
});
content.setOnScroll(evt -> {
if (evt.isControlDown()) {
evt.consume();
final double zoomFactor = evt.getDeltaY() > 0 ? 1.2 : 1 / 1.2;
Bounds groupBounds = group.getLayoutBounds();
final Bounds viewportBounds = scrollPane.getViewportBounds();
// calculate pixel offsets from [0, 1] range
double valX = scrollPane.getHvalue() * (groupBounds.getWidth() - viewportBounds.getWidth());
double valY = scrollPane.getVvalue() * (groupBounds.getHeight() - viewportBounds.getHeight());
// convert content coordinates to zoomTarget coordinates
Point2D posInZoomTarget = zoomTarget.parentToLocal(group.parentToLocal(new Point2D(evt.getX(), evt.getY())));
// calculate adjustment of scroll position (pixels)
Point2D adjustment = zoomTarget.getLocalToParentTransform().deltaTransform(posInZoomTarget.multiply(zoomFactor - 1));
// do the resizing
zoomTarget.setScaleX(zoomFactor * zoomTarget.getScaleX());
zoomTarget.setScaleY(zoomFactor * zoomTarget.getScaleY());
// refresh ScrollPane scroll positions & content bounds
scrollPane.layout();
// convert back to [0, 1] range
// (too large/small values are automatically corrected by ScrollPane)
groupBounds = group.getLayoutBounds();
scrollPane.setHvalue((valX + adjustment.getX()) / (groupBounds.getWidth() - viewportBounds.getWidth()));
scrollPane.setVvalue((valY + adjustment.getY()) / (groupBounds.getHeight() - viewportBounds.getHeight()));
}
});
StackPane left = new StackPane(new Label("Left Menu"));
SplitPane root = new SplitPane(left, scrollPane);
Scene scene = new Scene(root, 800, 600);
primaryStage.setScene(scene);
primaryStage.show();
}
示例2: populateMenu
import javafx.scene.layout.Region; //导入方法依赖的package包/类
private void populateMenu(Map<DocumentType, List<SearchResult>> results) {
contextMenu.getItems().clear();
for (Map.Entry<DocumentType, List<SearchResult>> entry : results.entrySet()) {
boolean first = true;
for(SearchResult result: entry.getValue()) {
final SearchResult sr = result;
final HBox hBox = new HBox();
hBox.setFillHeight(true);
Label itemLabel = new Label(result.getName());
itemLabel.getStyleClass().add("item-label");
if (first) {
first = false;
Label groupLabel = new Label(result.getDocumentType().getPluralDisplayName());
groupLabel.getStyleClass().add("group-label");
groupLabel.setAlignment(Pos.CENTER_RIGHT);
groupLabel.setMinWidth(USE_PREF_SIZE);
groupLabel.setPrefWidth(70);
hBox.getChildren().addAll(groupLabel,itemLabel);
} else {
Region spacer = new Region();
spacer.setMinWidth(USE_PREF_SIZE);
spacer.setPrefWidth(70);
hBox.getChildren().addAll(spacer,itemLabel);
}
// create a special node for hiding/showing popup content
final Region popRegion = new Region();
popRegion.getStyleClass().add("search-menu-item-popup-region");
popRegion.setPrefSize(10, 10);
hBox.getChildren().add(popRegion);
final String name = (result.getDocumentType() == DocumentType.SAMPLE) ? result.getName() :
result.getPackageName()+
((result.getClassName() != null) ? "."+result.getClassName() : "") +
((result.getName() != null) ? "."+result.getName() : "");
final String shortDescription = (result.getShortDescription().length() == 160) ? result.getShortDescription() +"..." : result.getShortDescription();
popRegion.opacityProperty().addListener(new ChangeListener<Number>() {
@Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
Platform.runLater( new Runnable() { // TODO runLater used here as a workaround for RT-14396
@Override public void run() {
if (popRegion.getOpacity() == 1) {
infoName.setText(name);
infoDescription.setText(shortDescription);
Point2D hBoxPos = hBox.localToScene(0, 0);
extraInfoPopup.show(getScene().getWindow(),
hBoxPos.getX() + contextMenu.getScene().getX() + contextMenu.getX() - infoBox.getPrefWidth() - 10,
hBoxPos.getY() + contextMenu.getScene().getY() + contextMenu.getY() - 27
);
}
}
});
}
});
// create menu item
CustomMenuItem menuItem = new CustomMenuItem(hBox, true);
menuItem.getStyleClass().add("search-menu-item");
contextMenu.getItems().add(menuItem);
// handle item selection
menuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) {
///System.out.println("SearchBox.handle menuItem.setOnAction");
Ensemble2.getEnsemble2().goToPage(sr.getEnsemblePath(),true);
}
});
}
}
}
示例3: initGraphics
import javafx.scene.layout.Region; //导入方法依赖的package包/类
private void initGraphics() {
main = new Region();
main.getStyleClass().setAll("main");
frame = new Region();
frame.getStyleClass().setAll("frame");
sectionsCanvas = new Canvas(width, barHeight);
sections = sectionsCanvas.getGraphicsContext2D();
currentValuePointer = new Region();
currentValuePointer.getStyleClass().setAll("normal-current-value-pointer");
currentValuePointer.setPrefSize(50, 20);
currentValuePointer.setCache(true);
currentValuePointer.setCacheHint(CacheHint.SPEED);
currentValueText = new Text(Double.toString(getSkinnable().getCurrentValue()));
currentValueText.getStyleClass().setAll("current-value-text");
currentValueText.setCache(true);
currentValueText.setCacheHint(CacheHint.SPEED);
currentValuePointerGroup = new Group(currentValuePointer, currentValueText);
currentValuePointerGroup.setCache(true);
currentValuePointerGroup.setCacheHint(CacheHint.SPEED);
titleText = new Text(getSkinnable().getTitle());
titleText.getStyleClass().setAll("title");
unitText = new Text(getSkinnable().getUnit());
unitText.getStyleClass().setAll("unit");
pane = new Pane();
pane.getChildren().setAll(main,
frame,
sectionsCanvas,
unitText,
titleText,
currentValuePointerGroup);
getChildren().setAll(pane);
resize();
}