本文整理汇总了Java中javafx.scene.Node.addEventFilter方法的典型用法代码示例。如果您正苦于以下问题:Java Node.addEventFilter方法的具体用法?Java Node.addEventFilter怎么用?Java Node.addEventFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.Node
的用法示例。
在下文中一共展示了Node.addEventFilter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MouseTracker
import javafx.scene.Node; //导入方法依赖的package包/类
public MouseTracker(final Node owner) {
owner.setOnMouseMoved(this.onMouseMovedEventHandler);
owner.setOnMouseClicked(this.onMouseClickedEventHandler);
owner.setOnMouseEntered(this.onMouseEnteredEventHandler);
owner.setOnMouseExited(this.onMouseExitedEventHandler);
owner.setOnMouseDragged(this.onMouseDraggedEventHandler);
owner.setOnMousePressed(this.onMousePressedEventHandler);
owner.setOnMouseReleased(this.onMouseReleasedEventHandler);
// Register our own event handler to register mouse placement at all times
owner.addEventFilter(MouseEvent.ANY, event -> {
if(!Double.isNaN(event.getX())) {
xProperty.set(event.getX());
}
if(!Double.isNaN(event.getY())) {
yProperty.set(event.getY());
}
});
}
示例2: setMouseListener
import javafx.scene.Node; //导入方法依赖的package包/类
protected void setMouseListener(Node node) {
node.addEventFilter(MouseEvent.MOUSE_CLICKED, (e) -> {
e.consume();
if (selectedItem != null) {
selectedItem.deselect();
}
selectedItem = CheckListItem.this;
CheckListItem.this.select();
});
}
示例3: start
import javafx.scene.Node; //导入方法依赖的package包/类
@Override public void start(Stage primaryStage) throws Exception {
TreeViewSample root = new TreeViewSample();
primaryStage.setScene(new Scene(root));
// primaryStage.getScene().getRoot().addEventFilter(MouseEvent.MOUSE_CLICKED,
// new EventHandler<Event>() {
// @Override
// public void handle(Event event) {
// Node source = (Node) event.getSource();
// MouseEvent me = (MouseEvent) event ;
// EventTarget target = event.getTarget();
// Node hit = getTarget((Node) event.getSource(), me.getX(), me.getY());
// if(hit != target) {
// System.err.println("Did not match");
// System.err.println("event-target = " + target);
// System.err.println("hit-target = " + hit);
// }
// }
//
// private Node getTarget(Node source, double x, double y) {
// List<Node> hits = new ArrayList();
// if(!(source instanceof Parent))
// return source;
// ObservableList<Node> children = ((Parent)
// source).getChildrenUnmodifiable();
// for (Node child : children) {
// Bounds boundsInParent = child.getBoundsInParent();
// x -= boundsInParent.getMinX();
// y -= boundsInParent.getMinY();
// if (x < 0.0 || y < 0.0)
// continue;
// checkHit(child, x, y, hits);
// }
// return hits.size() > 0 ? hits.get(hits.size() - 1) : source;
// }
//
// private void checkHit(Node child, double x, double y, List<Node>
// hits) {
// Bounds boundsInParent = child.getBoundsInParent();
// if(boundsInParent.contains(x, y)) {
// hits.add(child);
// if(!(child instanceof Parent))
// return ;
// x -= boundsInParent.getMinX();
// y -= boundsInParent.getMinY();
// ObservableList<Node> childrenUnmodifiable =
// ((Parent)child).getChildrenUnmodifiable();
// for (Node node : childrenUnmodifiable) {
// checkHit(node, x, y, hits);
// }
// }
// }
// });
primaryStage.show();
Set<Node> lookupAll = root.lookupAll(".text");
System.out.println("MyApp.start(): " + lookupAll.size());
for (Node node : lookupAll) {
node.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<Event>() {
@Override public void handle(Event event) {
MouseEvent me = (MouseEvent) event;
System.out.println("Bounds: " + ((Node) me.getSource()).getBoundsInParent());
System.out.println("Source Coords: " + me.getX() + ", " + me.getY());
System.out.println("Scene Coords: " + me.getSceneX() + ", " + me.getSceneY());
System.out.println("Screen Coords: " + me.getScreenX() + ", " + me.getScreenY());
}
});
}
}
示例4: suppressFocusStyleOnPress
import javafx.scene.Node; //导入方法依赖的package包/类
public static void suppressFocusStyleOnPress(Node node) {
node.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> suppressFocusStyle(node));
node.focusedProperty().addListener((v, o, n) -> endSuppressionIfFocusLost(node));
}
示例5: suppressFocusStyleOnRelease
import javafx.scene.Node; //导入方法依赖的package包/类
public static void suppressFocusStyleOnRelease(Node node) {
node.addEventFilter(MouseEvent.MOUSE_RELEASED, event -> suppressFocusStyle(node));
node.focusedProperty().addListener((v, o, n) -> endSuppressionIfFocusLost(node));
}