Java Code Examples for javafx.scene.layout.Pane#setOnMouseDragged()
The following examples show how to use
javafx.scene.layout.Pane#setOnMouseDragged() .
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: Exercise_15_18.java From Intro-to-Java-Programming with MIT License | 6 votes |
@Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane Pane pane = new Pane(); // Create a rectangle Rectangle rectangle = new Rectangle(5, 5, 30, 20); pane.getChildren().add(rectangle); // Create and register the handle pane.setOnMouseDragged(e -> { if (rectangle.contains(e.getX(), e.getY())) { pane.getChildren().clear(); rectangle.setX(e.getX() - rectangle.getWidth() * .5); rectangle.setY(e.getY() - rectangle.getHeight() * .5); pane.getChildren().add(rectangle); } }); // Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle("Exercise_15_18"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }
Example 2
Source File: Client.java From SynchronizeFX with GNU Lesser General Public License v3.0 | 6 votes |
private void addNote(final Note note) { final Pane newNote = new Pane(); final Position2D position = note.getPosition(); newNote.getChildren().add(new Label(note.getText())); newNote.styleProperty().set("-fx-background-color: red;"); newNote.setPrefSize(NOTE_WIDTH, NOTE_HEIGHT); newNote.layoutXProperty().bind(position.xProperty().multiply(root.widthProperty())); newNote.layoutYProperty().bind(position.yProperty().multiply(root.heightProperty())); newNote.setOnMouseDragged(new EventHandler<MouseEvent>() { @Override public void handle(final MouseEvent event) { position.setX(event.getSceneX() / root.getWidth()); position.setY(event.getSceneY() / root.getHeight()); event.consume(); } }); root.getChildren().add(newNote); notes.put(note, newNote); }
Example 3
Source File: DoodleTrace.java From gluon-samples with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Apply mouse listener events for desktop platforms. * @param drawSurface The drawing surface to receive mouse input. */ private void applyMouseInput(Pane drawSurface) { // starting initial path drawSurface.setOnMousePressed(mouseEvent -> start.path(mouseEvent.getX(), mouseEvent.getY())); // dragging creates lineTos added to the path drawSurface.setOnMouseDragged(mouseEvent -> draw.path(mouseEvent.getX(), mouseEvent.getY())); // end the path when mouse released event drawSurface.setOnMouseReleased(mouseEvent -> end.path(mouseEvent.getX(), mouseEvent.getY())); }
Example 4
Source File: Exercise_15_20.java From Intro-to-Java-Programming with MIT License | 5 votes |
@Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane Pane pane = new Pane(); // Create three points and add them to a list Circle p1 = new Circle(50, 100, 5); Circle p2 = new Circle(100, 25, 5); Circle p3 = new Circle(150, 80, 5); ArrayList<Circle> points = new ArrayList<>(); points.add(p1); points.add(p2); points.add(p3); // Place nodes in the pane drawTriangle(pane, points); pane.getChildren().addAll(p1, p2, p3); placeText(pane, points); // Create and register the handle pane.setOnMouseDragged(e -> { for (int i = 0; i < points.size(); i++) { if (points.get(i).contains(e.getX(), e.getY())) { pane.getChildren().clear(); points.get(i).setCenterX(e.getX()); points.get(i).setCenterY(e.getY()); drawTriangle(pane, points); pane.getChildren().addAll(p1, p2, p3); placeText(pane, points); } } }); // Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle("Exercise_15_20"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }
Example 5
Source File: Exercise_15_16.java From Intro-to-Java-Programming with MIT License | 5 votes |
@Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane Pane pane = new Pane(); // Create two circles Circle circle1 = new Circle(40, 40, 10); setProperties(circle1); Circle circle2 = new Circle(120, 150, 10); setProperties(circle2); // Place nodes in pane pane.getChildren().addAll(getLine(circle1, circle2), circle1, circle2, getText(circle1, circle2)); // Create and register the handle pane.setOnMouseDragged(e -> { if (circle1.contains(e.getX(), e.getY())) { pane.getChildren().clear(); circle1.setCenterX(e.getX()); circle1.setCenterY(e.getY()); pane.getChildren().addAll(getLine(circle1, circle2), circle1, circle2, getText(circle1, circle2)); } else if (circle2.contains(e.getX(), e.getY())) { pane.getChildren().clear(); circle2.setCenterX(e.getX()); circle2.setCenterY(e.getY()); pane.getChildren().addAll(getLine(circle1, circle2), circle1, circle2, getText(circle1, circle2)); } }); // Create a scene and place it in the stage Scene scene = new Scene(pane, 200, 200); primaryStage.setTitle("Exercise_15_16"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }