Java Code Examples for javafx.scene.shape.Rectangle#setX()
The following examples show how to use
javafx.scene.shape.Rectangle#setX() .
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: SeaBattle.java From games_oop_javafx with Apache License 2.0 | 6 votes |
private void buildShip(Group board, int desk, int startX, int startY) { Rectangle rect = new Rectangle(); rect.setX(startX); rect.setY(startY); rect.setHeight(25); rect.setWidth(desk * 25); rect.setFill(Color.BLACK); rect.setOnMouseDragged( event -> { rect.setX(event.getX()); rect.setY(event.getY()); } ); rect.setOnMouseReleased( event -> { rect.setX((((int) event.getX() / 25) * 25)); rect.setY(((int) event.getY() / 25) * 25); } ); rect.setOnMouseClicked( event -> { if (event.getButton() != MouseButton.PRIMARY) { Rectangle momento = new Rectangle(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); rect.setWidth(momento.getHeight()); rect.setHeight(momento.getWidth()); } } ); board.getChildren().add(rect); }
Example 2
Source File: PolygonLayoutBoundsBug.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override public void start(Stage primaryStage) throws Exception { final Polygon p = new Polygon(10, 30, 20, 20, 20, 40); p.setFill(Color.RED); p.setStroke(Color.BLACK); final Rectangle r = new Rectangle(); r.setFill(new Color(0, 0, 1, 0.5)); r.setX(p.getLayoutBounds().getMinX()); r.setY(p.getLayoutBounds().getMinY()); r.setWidth(p.getLayoutBounds().getWidth()); r.setHeight(p.getLayoutBounds().getHeight()); Group g = new Group(r, p); g.getTransforms().add(new Scale(10, 10)); Scene scene = new Scene(g, 500, 500); primaryStage.setScene(scene); primaryStage.sizeToScene(); primaryStage.show(); }
Example 3
Source File: ImagePanel.java From marathonv5 with Apache License 2.0 | 6 votes |
void adjust_rectangle_properties(double starting_point_x, double starting_point_y, double ending_point_x, double ending_point_y, Rectangle given_rectangle) { given_rectangle.setX(starting_point_x); given_rectangle.setY(starting_point_y); given_rectangle.setWidth(ending_point_x - starting_point_x); given_rectangle.setHeight(ending_point_y - starting_point_y); if (given_rectangle.getWidth() < 0) { given_rectangle.setWidth(-given_rectangle.getWidth()); given_rectangle.setX(given_rectangle.getX() - given_rectangle.getWidth()); } if (given_rectangle.getHeight() < 0) { given_rectangle.setHeight(-given_rectangle.getHeight()); given_rectangle.setY(given_rectangle.getY() - given_rectangle.getHeight()); } }
Example 4
Source File: PackMan.java From games_oop_javafx with Apache License 2.0 | 6 votes |
private Rectangle buildFigure(int x, int y, int size, String image) { Rectangle rect = new Rectangle(); rect.setX(x); rect.setY(y); rect.setHeight(size); rect.setWidth(size); Image img = new Image(this.getClass().getClassLoader().getResource(image).toString()); rect.setFill(new ImagePattern(img)); return rect; }
Example 5
Source File: Chess.java From games_oop_javafx with Apache License 2.0 | 5 votes |
private Rectangle buildRectangle(int x, int y, int size, boolean white) { Rectangle rect = new Rectangle(); rect.setX(x * size); rect.setY(y * size); rect.setHeight(size); rect.setWidth(size); if (white) { rect.setFill(Color.WHITE); } else { rect.setFill(Color.GRAY); } rect.setStroke(Color.BLACK); return rect; }
Example 6
Source File: PageView.java From latexdraw with GNU General Public License v3.0 | 5 votes |
/** * Creates a view of a page. * @param origin The origin point where the page has to be placed. Cannot be null. */ public PageView(final @NotNull PreferencesService prefs, final Point origin) { super(); recPage = new Rectangle(); recShadowBottom = new Rectangle(); recShadowRight = new Rectangle(); recPage.setStrokeWidth(1d); recPage.setStroke(Color.BLACK); recPage.setFill(null); recPage.setX(origin.getX()); recPage.setY(origin.getY()); recShadowRight.setStroke(null); recShadowBottom.setStroke(null); recShadowRight.setFill(Color.GRAY); recShadowBottom.setFill(Color.GRAY); getChildren().add(recShadowBottom); getChildren().add(recShadowRight); getChildren().add(recPage); recPage.toFront(); setMouseTransparent(true); setFocusTraversable(false); update(prefs.getPage()); prefs.pageProperty().addListener((observable, oldValue, newValue) -> update(newValue)); }
Example 7
Source File: JavaFxGazeUtils.java From tet-java-client with BSD 2-Clause "Simplified" License | 5 votes |
private static boolean checkViewCollision(Node n, Point2D gaze, Rectangle roi) { javafx.geometry.Point2D screenCoord = n.localToScreen(0d, 0d); roi.setX(Math.round(screenCoord.getX())); roi.setY(Math.round(screenCoord.getY())); roi.setWidth(n.getBoundsInParent().getWidth()); roi.setHeight(n.getBoundsInParent().getHeight()); return roi.contains( (int)Math.round(gaze.x), (int)Math.round(gaze.y) ); }
Example 8
Source File: BendConnectionPolicyTests.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override protected void doRefreshVisual(final Rectangle visual) { final org.eclipse.gef.geometry.planar.Rectangle rect = ((org.eclipse.gef.geometry.planar.IShape) getContent()) .getBounds(); visual.setX(rect.getX()); visual.setY(rect.getY()); visual.setWidth(rect.getWidth()); visual.setHeight(rect.getHeight()); }
Example 9
Source File: NodePropertiesSample.java From marathonv5 with Apache License 2.0 | 5 votes |
public NodePropertiesSample() { super(300,100); //X position of node = X + LayoutX + TranslateX rectA = new Rectangle(50, 50, Color.LIGHTSALMON); //set position of node temporary (can be changed after) rectA.setTranslateX(10); rectB = new Rectangle(50, 50, Color.LIGHTGREEN); //set position of node when addinf to some layout rectB.setLayoutX(20); rectB.setLayoutY(10); rectC = new Rectangle(50, 50, Color.DODGERBLUE); //last posibility of setting X position of node rectC.setX(30); rectC.setY(20); //opacity of node can be set rectC.setOpacity(0.8); // REMOVE ME setControls( new SimplePropertySheet.PropDesc("Rectangle A translate X", rectA.translateXProperty(), 0d, 50d), new SimplePropertySheet.PropDesc("Rectangle B translate X", rectB.translateXProperty(), 0d, 50d), new SimplePropertySheet.PropDesc("Rectangle C translate X", rectC.translateXProperty(), 0d, 50d), new SimplePropertySheet.PropDesc("Rectangle A Opacity", rectA.opacityProperty(), 0d, 1d), new SimplePropertySheet.PropDesc("Rectangle B Opacity", rectB.opacityProperty(), 0d, 1d), new SimplePropertySheet.PropDesc("Rectangle C Opacity", rectC.opacityProperty(), 0d, 1d) ); getChildren().add(createRadioButtons()); // END REMOVE ME Group g = new Group(rectA, rectB, rectC); g.setLayoutX(160 + 35); getChildren().addAll(g); }
Example 10
Source File: NodePropertiesSample.java From marathonv5 with Apache License 2.0 | 5 votes |
public NodePropertiesSample() { super(300,100); //X position of node = X + LayoutX + TranslateX rectA = new Rectangle(50, 50, Color.LIGHTSALMON); //set position of node temporary (can be changed after) rectA.setTranslateX(10); rectB = new Rectangle(50, 50, Color.LIGHTGREEN); //set position of node when addinf to some layout rectB.setLayoutX(20); rectB.setLayoutY(10); rectC = new Rectangle(50, 50, Color.DODGERBLUE); //last posibility of setting X position of node rectC.setX(30); rectC.setY(20); //opacity of node can be set rectC.setOpacity(0.8); // REMOVE ME setControls( new SimplePropertySheet.PropDesc("Rectangle A translate X", rectA.translateXProperty(), 0d, 50d), new SimplePropertySheet.PropDesc("Rectangle B translate X", rectB.translateXProperty(), 0d, 50d), new SimplePropertySheet.PropDesc("Rectangle C translate X", rectC.translateXProperty(), 0d, 50d), new SimplePropertySheet.PropDesc("Rectangle A Opacity", rectA.opacityProperty(), 0d, 1d), new SimplePropertySheet.PropDesc("Rectangle B Opacity", rectB.opacityProperty(), 0d, 1d), new SimplePropertySheet.PropDesc("Rectangle C Opacity", rectC.opacityProperty(), 0d, 1d) ); getChildren().add(createRadioButtons()); // END REMOVE ME Group g = new Group(rectA, rectB, rectC); g.setLayoutX(160 + 35); getChildren().addAll(g); }
Example 11
Source File: Chess.java From games_oop_javafx with Apache License 2.0 | 5 votes |
private Rectangle buildFigure(int x, int y, int size, String image) { Rectangle rect = new Rectangle(); rect.setX(x); rect.setY(y); rect.setHeight(size); rect.setWidth(size); Image img = new Image(this.getClass().getClassLoader().getResource(image).toString()); rect.setFill(new ImagePattern(img)); final Rectangle momento = new Rectangle(x, y); rect.setOnDragDetected( event -> { momento.setX(event.getX()); momento.setY(event.getY()); } ); rect.setOnMouseDragged( event -> { rect.setX(event.getX() - size / 2); rect.setY(event.getY() - size / 2); } ); rect.setOnMouseReleased( event -> { try { logic.move( this.findBy(momento.getX(), momento.getY()), this.findBy(event.getX(), event.getY())); rect.setX(((int) event.getX() / 40) * 40 + 5); rect.setY(((int) event.getY() / 40) * 40 + 5); } catch (Exception e) { Alert info = new Alert(Alert.AlertType.ERROR); info.setContentText(e.getClass().getName() + " " + e.getMessage()); info.show(); rect.setX(((int) momento.getX() / 40) * 40 + 5); rect.setY(((int) momento.getY() / 40) * 40 + 5); } } ); return rect; }
Example 12
Source File: SCUtils.java From scenic-view with GNU General Public License v3.0 | 5 votes |
static void updateRect(final Parent overlayParent, final Node node, final Bounds bounds, final double tx, final double ty, final Rectangle rect) { final Bounds b = toSceneBounds(overlayParent, node, bounds, tx, ty); rect.setX(b.getMinX()); rect.setY(b.getMinY()); rect.setWidth(b.getMaxX() - b.getMinX()); rect.setHeight(b.getMaxY() - b.getMinY()); }
Example 13
Source File: PackMan.java From games_oop_javafx with Apache License 2.0 | 5 votes |
private Rectangle buildRectangle(int x, int y, int size) { Rectangle rect = new Rectangle(); rect.setX(x * size); rect.setY(y * size); rect.setHeight(size); rect.setWidth(size); rect.setFill(Color.WHITE); rect.setStroke(Color.BLACK); return rect; }
Example 14
Source File: Puzzle.java From games_oop_javafx with Apache License 2.0 | 5 votes |
private Rectangle buildFigure(int x, int y, int size, String image) { Rectangle rect = new Rectangle(); rect.setX(x); rect.setY(y); rect.setHeight(size); rect.setWidth(size); Image img = new Image(this.getClass().getClassLoader().getResource(image).toString()); rect.setFill(new ImagePattern(img)); final Rectangle momento = new Rectangle(x, y); rect.setOnDragDetected( event -> { momento.setX(event.getX()); momento.setY(event.getY()); } ); rect.setOnMouseDragged( event -> { rect.setX(event.getX() - size / 2); rect.setY(event.getY() - size / 2); } ); rect.setOnMouseReleased( event -> { if (logic.move(this.extract(momento.getX(), momento.getY()), this.extract(event.getX(), event.getY()))) { rect.setX(((int) event.getX() / 40) * 40 + 5); rect.setY(((int) event.getY() / 40) * 40 + 5); checkWinner(); } else { rect.setX(((int) momento.getX() / 40) * 40 + 5); rect.setY(((int) momento.getY() / 40) * 40 + 5); } } ); return rect; }
Example 15
Source File: Puzzle.java From games_oop_javafx with Apache License 2.0 | 5 votes |
private Rectangle buildRectangle(int x, int y, int size) { Rectangle rect = new Rectangle(); rect.setX(x * size); rect.setY(y * size); rect.setHeight(size); rect.setWidth(size); rect.setFill(Color.WHITE); rect.setStroke(Color.BLACK); return rect; }
Example 16
Source File: SeaBattle.java From games_oop_javafx with Apache License 2.0 | 5 votes |
private Rectangle buildRectangle(int x, int y, int size) { Rectangle rect = new Rectangle(); rect.setX(x * size); rect.setY(y * size); rect.setHeight(size); rect.setWidth(size); rect.setFill(Color.WHITE); rect.setStroke(Color.BLACK); return rect; }
Example 17
Source File: Piece.java From DevToolBox with GNU Lesser General Public License v2.1 | 5 votes |
private Rectangle createPieceRectangle() { Rectangle rec = new Rectangle(); rec.setX(-50); rec.setY(-50); rec.setWidth(SIZE); rec.setHeight(SIZE); return rec; }
Example 18
Source File: TransformPolicyTests.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override protected void doRefreshVisual(Rectangle visual) { visual.setX(getContent().x); visual.setY(getContent().y); }
Example 19
Source File: BlendEffect.java From Learn-Java-12-Programming with MIT License | 4 votes |
private static Rectangle createSquare(int x, int y){ Rectangle r = createSquare(); r.setX(x); r.setY(y); return r; }