本文整理汇总了Java中javafx.scene.layout.Region.setOnMousePressed方法的典型用法代码示例。如果您正苦于以下问题:Java Region.setOnMousePressed方法的具体用法?Java Region.setOnMousePressed怎么用?Java Region.setOnMousePressed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.layout.Region
的用法示例。
在下文中一共展示了Region.setOnMousePressed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateView
import javafx.scene.layout.Region; //导入方法依赖的package包/类
private void updateView(Region oldValue, Region newValue) {
if (oldValue != null) {
oldValue.scaleXProperty().unbind();
oldValue.scaleYProperty().unbind();
oldValue.setOnMousePressed(null);
oldValue.setOnMouseDragged(null);
}
Objects.requireNonNull(newValue);
newValue.setManaged(false);
newValue.addEventFilter(MouseEvent.MOUSE_PRESSED, evt -> {
mouseX = evt.getSceneX();
mouseY = evt.getSceneY();
});
newValue.addEventFilter(MouseEvent.MOUSE_DRAGGED, evt -> {
double deltaX = evt.getSceneX() - mouseX;
double deltaY = evt.getSceneY() - mouseY;
newValue.relocate(newValue.getLayoutX() + deltaX, newValue.getLayoutY() + deltaY);
mouseX = evt.getSceneX();
mouseY = evt.getSceneY();
});
scale.unbind();
scale.bind(Bindings.multiply(Bindings.min(scaleX, scaleY), getSkinnable().zoomProperty()));
scaleX.unbind();
scaleX.bind(Bindings.min(1, Bindings.divide(Bindings.multiply(INITIAL_SCALE_FACTOR, getSkinnable().widthProperty()), newValue.widthProperty())));
scaleY.unbind();
scaleY.bind(Bindings.min(1, Bindings.divide(Bindings.multiply(INITIAL_SCALE_FACTOR, getSkinnable().heightProperty()), newValue.heightProperty())));
newValue.scaleXProperty().bind(scale);
newValue.scaleYProperty().bind(scale);
getChildren().setAll(newValue);
}
示例2: makeResizable
import javafx.scene.layout.Region; //导入方法依赖的package包/类
public static void makeResizable(Region region) {
final DragResizerXY resizer = new DragResizerXY(region);
region.setOnMousePressed(resizer::mousePressed);
region.setOnMouseDragged(resizer::mouseDragged);
region.setOnMouseMoved(resizer::mouseOver);
region.setOnMouseReleased(resizer::mouseReleased);
}